prabu
prabu

Reputation: 6171

How to open popup windows in background using javascript?

Is it possible to open pop-up windows BEHIND the current active screen using java script?

 var win= window.open(value,'_blank');

the above script opens pop windows in browser tab but I loss active page from my sight.

any suggestion?

Thanks in advance

Solution:

As per @Brian advised,

var win=window.open(value,null,"height=400,width=600,status=yes,toolbar=no,scrollbars=yes,menubar=no,location=no");
win.blur();

Its works in IE,FireFox and safari but not in Chrome browser.

Can any one suggest how to open multiple popup boxes in IE browser? The above script will open only one pop up in IE.

Upvotes: 3

Views: 24877

Answers (4)

jibiel
jibiel

Reputation: 8303

For more cross-browser solution I'd suggest to take a look at this script — jquery-popunder:

...was tested with:

  • Mozilla Firefox 3-19
  • Google Chrome 10-25
    • Note: Currently you can only create 2 popunder in Chrome 22-24
    • Note: In Chrome 23-24 you'll need a separate event for the popunder-effect (see the examples!)
  • Microsoft Internet Explorer 6-9
  • Apple Safari 5

    Known issues:

  • the script does not work with the Opera-Browser, so the opera-browser is disable by default
  • the script does not work in Firefox under Gnome
  • in Firefox, when the setting: 'Open new windows in a new tab instead' is deactivated

Note that

This script will only work, if the popunder is opened on a user-generated event (e.g. click or submit).

Upvotes: 1

Liam
Liam

Reputation: 19

I found that with Firefox it was not possible to push the window to the back, no matter how much of the code I modified. Ultimately I settled for making the window small enough 10, 10 so that it appeared in one of the corners and was barely perceived by the visitor.

var win=window.open(value,null,"height=10,width=10,status=yes,toolbar=no,scrollbars=yes,menubar=no,location=no");

Chrome opens the popup/under in a tab and iE does place it in the background, behind the active window.

Upvotes: 1

nickf
nickf

Reputation: 546035

+1 to Brian's answer to refocus the original window afterwards. If you, for some reason, always want it to be behind, you can use the alwaysLowered property:

alwaysLowered
If set to yes, the new created window floats below, under its own parent when the parent window is not minimized. alwaysLowered windows are often referred as pop-under windows. The alwaysLowered window can not be on top of the parent but the parent window can be minimized. In NS 6.x, the alwaysLowered window has no minimize system command icon and no restore/maximize system command.

Good documentation of all the available features can be found on the MDC window.open page.

Upvotes: 3

Brian
Brian

Reputation: 2778

You can add:

win.blur();

... to your code ...

Or

this.window.focus();

Upvotes: 8

Related Questions