在Chrome中两次设置location.href [英] setting location.href twice in chrome

查看:111
本文介绍了在Chrome中两次设置location.href的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用

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:...">
<a id="link2" href="javascript:...">

该代码在Firefox中工作正常,但在Chrome中仅执行最后一个location.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?

推荐答案

我也遇到类似的情况.我通过使用setTimeout函数将第二个延迟一下来解决了这个问题,并且效果很好.

I had a similar situation. I solved it by using setTimeout function to delay the second one a bit and it works fine.

这篇关于在Chrome中两次设置location.href的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆