简体   繁体   中英

location.href only working in Chrome

[Edit: ok, my bad. The redirect works, it's an error in app.php that immediately redirects back to index.php. Thanks for your help though :) ]

So I'm building this Facebook-app where, after a bunch of steps, you're redirected (inside an iframe) to a PHP file named app.php. This redirect is done using JS:

// this is in 'join-app.js':
location.href = "app.php?userid=" + userdata.id;

This bit of JS is in a seperate .js-file (join-app.js) which is loaded into index.php:

<!-- this is in 'index.php': -->
<script language="javascript" type="text/javascript" src="js/join-app.js"></script>

index.php is the source of the iframe on Facebook.

The above works fine in Chrome on OS X, but for some reason it does not work in Safari on OS X, or IE on Windows. It does work on Firefox on OS X and Windows... In IE and Safari, the index.php page just keeps getting reloaded.

For redirects in JavaScript, it is usual to use window.location :

<script type="text/javascript">
   <!--
      window.location = "http://www.google.com/"
   //-->
</script>

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