最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I open a pop-up window without it being blocked? - Stack Overflow

programmeradmin0浏览0评论

I haven't found a single answer able to tell me what's the right way to open a popup.

Times have changed, and popups have been mostly replaced with fancybox-like boxes. However, there are still times when popups are needed.

For those cases, I don't want my popup to be blocked by the browsers.

What's the right way to open a popup without it being blocked? Even if it opens a new tab in the browser. I just want my popup to be open, and have control of it from the parent or vice versa.

I haven't found a single answer able to tell me what's the right way to open a popup.

Times have changed, and popups have been mostly replaced with fancybox-like boxes. However, there are still times when popups are needed.

For those cases, I don't want my popup to be blocked by the browsers.

What's the right way to open a popup without it being blocked? Even if it opens a new tab in the browser. I just want my popup to be open, and have control of it from the parent or vice versa.

Share Improve this question edited Jan 23, 2014 at 12:51 Quentin 945k132 gold badges1.3k silver badges1.4k bronze badges asked Jan 23, 2014 at 12:41 Florian MargaineFlorian Margaine 60.8k15 gold badges93 silver badges120 bronze badges 1
  • then check this one stackoverflow./questions/9514698/… – Mr.Geeker Commented May 21, 2014 at 17:05
Add a ment  | 

2 Answers 2

Reset to default 6

Popup blockers will block any popup, unless it is opened because of an user action.

If the user clicks on a link, and a popup is opened in the click listener of that link, the popup blocker knows the user want to open something and will not (or should not) block the popup.

What you cannot do:

  • open a popup when the page is opened or closed
  • open a popup after a certain interval
  • open a popup after something asynchronous happens

What you can do:

  • open a popup in the on click listener
  • using target="_blank" in a anchor tag

You can access both windows with JavaScript variables:

  • if you use window.open, the parent can have a reference to the popup by assigning the result of window.open to a variable. Check out this article at W3Schools.
  • If the popup needs to have access to the window who has opened it, you can use window.opener. Check out this question.

try this, it works for me

$('#myButton').click(function () {
    var redirectWindow = window.open('http://google.', '_blank');
    redirectWindow.location;
});

Js fiddle for this is here https://jsfiddle/safeeronline/70kdacL4/2/

if you want to open new tab after ajax call see this fiddle http://jsfiddle/safeeronline/70kdacL4/1/

发布评论

评论列表(0)

  1. 暂无评论