How to do http-equiv redirect that saves query_string and fragment_id

In Javascript, I can redirect and save the query string and fragment id as follows:

window.location = "NEW_LOCATION" + window.location.search + window.location.hash;

For sites without Javascript, you can use http-equiv meta header. But this reduces the query string and fragment id:

<head>
    <meta http-equiv="Refresh" content="300; url=NEW_LOCATION" />
</head>

Is there a way to make an equivalent using http-equiv = "refresh", which saves the query string and fragment identifier?

+5
source share
3 answers

Not without a server-side scripting language that puts the correct URL in the HTML tag (or sends the header directly Refresh).

+1
source

JavaScript .

. IE8 + noscript JavaScript. html, script .

<!DOCTYPE html>
<html data-destination="http://stackoverflow.com">
  <head>
    <noscript><meta id="redirect" http-equiv="refresh" content="0; url=http://stackoverflow.com"></noscript>
  </head>

  <body>
    This page has moved. Redirecting...
    
  <!-- Redirect in JavaScript with meta refresh fallback above in noscript -->
  <script>
  var destination = document.documentElement.getAttribute('data-destination');
  window.location.href = destination + (window.location.search || '') + (window.location.hash || '');
  </script>
  </body>
</html>
Hide result
+4

Script ( , ). URL ( "hidAutoURL" ) ( ).

document.write meta.

<BODY>

    <FORM>
    </FORM>

    <script>
        function getAutoURL()
        {
            var url = document.getElementById('hidAutoURL').value;
            return url;
        }

        //Update META for auto-refresh
        var configuredTime = document.getElementById('hidRefrTime').value;
        var content = configuredTime + ';url=' + getAutoURL('url');
        document.write('<meta http-equiv="refresh" content="'+content + '"/>');

    </script>

</BODY>

0

All Articles