Difference between a.click() in Firefox and Google
巴扎黑
巴扎黑 2017-07-05 11:01:11
0
2
732

code show as below

<!-- test.html -->
<button>Click</button>
//test.js
var btn = document.querySelector('button')
btn.onclick = () => {
    var a = document.createElement('a')
    a.href = 'https://www.baidu.com'
    a.target = '_blank'
    a.click()
}

Questions are as follows:

There is no response when clicking the button in Firefox, but you can create a new tab page by clicking the button in Google;
Add a statement to test.js

var btn = document.querySelector('button')
btn.onclick = () => {
    var a = document.createElement('a')
    a.href = 'https://www.baidu.com'
    a.target = '_blank'
    
    document.body.appendChild(a)
    
    a.click()
}

The rewritten code can run normally in both browsers. So I would like to ask my friends what is the reason for this, thank you?

巴扎黑
巴扎黑

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!