How to do a http

In Javascript I can redirect and preserve the query string and fragment ID like this:

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

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

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

Is there a way to do the equivalent using http-equiv="refresh" that preserves the query string and fragment ID?


不是没有服务器端脚本语言,它将正确的URL放入HTML标记中(或直接发送Refresh标题)。


You could use JavaScript to update the meta tag with the query string and hash.

Update A better approach for IE8+ would be a noscript tag and a JavaScript powered redirect. Add the redirect as data-destination attribute on the html element so the script can grab it easily.

<!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>

I am using the following Script (after the Form, but before end of body). Required URL ("hidAutoURL") is stored in a hidden variable first (from the server side).

document.write is used to update the 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>

References

  • What is the correct way to write HTML using Javascript?
  • Changing the content of meta refresh does not change refreshing time
  • Using document.write
  • 链接地址: http://www.djcxy.com/p/12412.html

    上一篇: 无法使用标题

    下一篇: 如何做一个http