简体   繁体   中英

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

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.

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.com', '_blank');
    redirectWindow.location;
});

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

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

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