简体   繁体   中英

JAVASCRIPT/AJAX reload a page if cookie exists else stay on page

I code mainly serverside with PHP and I ran into a situation where I need to reload the page based on user input. I set a cookie "reload" with value "1" and need a javascript or AJAX to check for it in real time. If the cookie exists, this script needs to trigger the event

 window.location.href="samplepage.php" 

I am really new here so hope this question is in right forum. Thanks for any help!

if (document.cookie.indexOf('reload') > -1 ) {
  window.location.href="samplepage.php" ;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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