在Firefox如何实现链接的click()?

coeltdit 2007-04-22 01:37:31
在Firefox如何实现链接的click() ?

想要通过脚本点击一个链接。

是像这样的情况:

<a href="http://www.abc.com" id="abc">abc</a>

document.getElementById("abc").click()

在IE和opera中正常,在firefox不行.

不要用document.location.href=url的方法来实现,还有其它方法吗?
...全文
360 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
feixian49 2009-09-11
  • 打赏
  • 举报
回复
mark
hotup 2009-09-09
  • 打赏
  • 举报
回复
firefox下你死心吧,下边是官网看到的...模模糊糊的还是看到了 tag
---------------------------------------------------------------------
Gecko DOM Reference Summary The click method simulates a click on an element. Syntax element.click() Notes The click method is intended to be used with INPUT elements of type button, checkbox, radio, reset or submit. Gecko does not implement the click method on other elements that might be expected to respond to mouse–clicks such as links (A elements), nor will it necessarily fire the click event of other elements. Non–Gecko DOMs may behave differently. When a click is used with elements that support it (e.g. one of the INPUT types listed above), it also fires the element's click event which will bubble up to elements higher up the document tree (or event chain) and fire their click events too. However, bubbling of a click event will not cause an A element to initiate navigation as if a real mouse-click had been received. Specification click
---------------------------------------------------------------------------
muxrwc 2007-04-22
  • 打赏
  • 举报
回复
a那个元素不可以。。
你还是换方法吧。。按钮可以。。

<input id="abc" type="button" onclick="alert('wc')" />
<script type="text/javascript">
var $ = function (id) {
return document.getElementById(id);
};

a = $("abc");
if (!document.createEvent) {
a.click();
} else {
var o = a.ownerDocument.createEvent("MouseEvents");
o.initEvent("click", false, true);
a.dispatchEvent(o);
}
</script>

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧