简体   繁体   中英

Why does chrome allow window.open() to work when executed in the console but not in the code file itself?

I have a web page which i have set to block popups from displaying:

在此处输入图片说明

If i execute the following code on page load, the browser blocks the tab from being opened:

window.open("http://www.google.com","test",'scrollbars=yes, width=' + 100 + ', height=' + 100 + ', top=' + 100 + ', left=' + 100)

However if i type the exact same code and execute through the debugger console, the popup works despite being blocked.

Likewise if i set up an <a/> tag with a click event bound to it which will execute the same code, that also works.

Why is there a discrepancy here?

The browser tracks whether the current dispatch of the browser's event thread was initiated by a direct user action -- such as entering a command at the console, or clicking on a link. Only when a direction action has been taken can a window or tab be opened.

I've noticed recently that Firefox lets multiple windows be opened in response to a user action, Chrome limits it to one window.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM