通过 javascript 模拟点击锚标记
我试图通过 javascript 模拟点击锚标记来更改浏览器地址框中的文本。这段代码在 IE 中工作得很好,但在 FireFox 或 Chrome 中却不行。
<script type="text/javascript">
function UpdateQueryString() {
var controlRef = document.createElement('a');
controlRef.id = "t1";
controlRef.href = '#1';
controlRef.innerHTML = '';
document.body.appendChild(controlRef);
try {
controlRef.click();
}
catch (err) {
txt = "There was an error on this page.\n\n";
txt += "Error description: " + err.description + "\n\n";
txt += "Click OK to continue.\n\n";
alert(txt);
}
return false;
}
</script>
在 IE 以外的浏览器中,我可以找到锚标记,但调用 click 会导致错误。
谢谢
I am trying to change the text in browser's address box by simulating a click on an anchor tag via javascript. This code works just fine in IE, but not in FireFox or Chrome.
<script type="text/javascript">
function UpdateQueryString() {
var controlRef = document.createElement('a');
controlRef.id = "t1";
controlRef.href = '#1';
controlRef.innerHTML = '';
document.body.appendChild(controlRef);
try {
controlRef.click();
}
catch (err) {
txt = "There was an error on this page.\n\n";
txt += "Error description: " + err.description + "\n\n";
txt += "Click OK to continue.\n\n";
alert(txt);
}
return false;
}
</script>
In browsers other than IE, I can find the anchor tag, but calling the click results in an error.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在查找
location
属性:或者
You're looking for the
location
property:or