setting location.href twice in chrome
I'm using
location.href=document.getElementById("link1").href;
location.href=document.getElementById("link2").href;
to run the scripts associated to the links:
<a id="link1" href="javascript:..."&g开发者_StackOverflow社区t;
<a id="link2" href="javascript:...">
The code works fine in Firefox, but in Chrome only the last location.href command (and so only the second piece of javascript code) is executed. How can I force it to execute both the first time and the second one?
I had a similar situation. I solved it by using setTimeout
function to delay the second one a bit and it works fine.
Try putting your javascript code into functions.
You can then call those functions from the links when they are clicked, as well as anywhere else you need them. This is a much more stable way of running code rather than with urls.
精彩评论