简体   繁体   English

Cookie onload事件页面重定向

[英]cookie onload event page redirect

How to perform any action after cookie load completed. Cookie加载完成后如何执行任何操作。 eg we have to redirect the url after cookie load complete. 例如,我们必须在cookie加载完成后重定向URL。

$(document).ready(function() {  // Handler for .ready() called. });

We have cookie loaded after page load through javascript. 通过javascript页面加载后,我们已经加载了cookie。 So i dont have option but to wait till the cookie is completely loaded and page redirect. 因此,我别无选择,只能等到cookie完全加载和页面重定向为止。

cookies are sent through HTTP headers, so you can load them anywhere and performs the redirect action in your page even on <head> block. Cookie是通过HTTP标头发送的,因此您可以将它们加载到任何位置,甚至在<head>块上也可以在页面中执行重定向操作。

Here jQuery is not necessary, just execute a location.href = ... 在这里jQuery不是必需的,只需执行一个location.href = ...

The cookies are sent in the response header (unless doing them after page load via javascript), so you don't even have to wait until document ready. Cookie会在响应标头中发送(除非通过javascript在页面加载后进行处理),因此您甚至不必等到文档准备就绪。 You could make a javascript redirect be the very first content given to the browser, no need to wait for the page to load. 您可以将javascript重定向作为提供给浏览器的第一内容,而无需等待页面加载。

Through typically in such situations, you may just want to handle this whole thing on the server (ie not rely on javascript at all). 通常,在这种情况下,您可能只想在服务器上处理整个事情(即完全不依赖javascript)。

You may try the following 您可以尝试以下

<head>
  <script>
    if(condition){
      window.location = "http://yournewlocation.com";
    }
  </script>
</head>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM