javascript - anchor 击功能在 Firefox 中不起作用

标签 javascript firefox anchor

这段代码:

a = document.createElement('a')
a.setAttribute('href','http://www.google.de')
a.click()

在 chrome 中工作。它按预期打开 www.google.de。但在 Firefox 中它什么都不做。 为什么以及如何让它发挥作用?

我在 ubuntu linux 15.04 上使用 firefox 40.0.3。

最佳答案

使用以下内容:

var a = document.createElement('a')
a.setAttribute('href','http://www.google.de');
document.getElementsByTagName('body')[0].appendChild(a);
a.click();

关于javascript - anchor 击功能在 Firefox 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32285899/

相关文章:

javascript - 动态事件处理程序

firefox - Angular xhr 请求在 Firefox 中导致重定向警告

css - 使用 anchor 链接时菜单栏隐藏 div

c# - C# WebBrowser 控件中带有 HTML anchor 的奇怪浏览器行为

javascript - 每当离开元素时,qTip2 总是关闭

javascript - 删除属性或构造仅具有所需属性的新对象更快吗?

javascript - Window.open + 移动设备 + Canvas == 不工作?

java - Selenium : Expected [object Undefined] 的 Java 错误

google-chrome - 为什么 View Source 会发出新的 HTTP 请求?

lua 不处理 string.find 或 string.match 中的 anchor