这段代码:
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/