简体   繁体   English

现代浏览器会阻止吗

[英]Do modern browsers block <a href="javascript:window.open…?

I want to pop up a window for people to share to Facebook. 我想弹出一个窗口供人们分享到Facebook。

The only way to do this is through javascript. 唯一的方法是通过javascript。 (pop up a small window width=400, height=200) (弹出一个小窗口,宽度= 400,高度= 200)

Will Chrome/IE/Google pop up blockers block this? Chrome / IE / Google弹出窗口阻止程序会阻止此行为吗?

How to get around it? 如何解决呢?

Modern browsers will not block what you're attempting to do. 现代浏览器不会阻止您尝试执行的操作。

All modern browsers do implement tech to block popups. 所有现代的浏览器均采用技术来阻止弹出窗口。 What this means is all window.open calls must be within a click event handler, or within a function called by said handler. 这意味着所有window.open调用都必须在click事件处理程序中,或在所述处理程序调用的函数中。 As long as you are creating a pop up in response to a user action you should be fine. 只要您正在创建弹出窗口来响应用户操作,就可以了。

If you are attempting to call window.open as soon as the dom is loaded, or after a short delay (example: setTimeout(50, window.open())) then it will be blocked. 如果您尝试在dom加载后立即调用window.open,或者在短暂延迟后调用(例如:setTimeout(50,window.open())),则它将被阻止。

Don't use popups – use a javascript modal window, with the href pointed to real content if appropriate. 不要使用弹出窗口-使用javascript模式窗口,适当时href指向实际内容。

For most users, popups are very annoying. 对于大多数用户而言,弹出窗口非常令人讨厌。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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