Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Test for a popunder working in ff 3-14, chrome 10-21, ie6-9
<!DOCTYPE html>
<html>
<head>
<meta content="Hans-Peter Buniat" name="author">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Form-Submit Popunder</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
</head>
<body>
<form id="testSubmit" action="http://www.google.com">
<input type="submit" />
</form>
<script type="text/javascript">
/* use jQuery as container for more convenience */
(function($) {
/**
* Create a popunder
*
* @param sUrl Url to open as popunder
*
* @return jQuery
*/
$.popunder = function(sUrl) {
var bSimple = $.browser.msie,
run = function() {
$.popunderHelper.open(sUrl, bSimple);
};
(bSimple) ? run() : window.setTimeout(run, 1);
return $;
};
/* several helper functions */
$.popunderHelper = {
/**
* Helper to create a (optionally) random value with prefix
*
* @param string name
* @param boolean rand
*
* @return string
*/
rand: function(name, rand) {
var p = (name) ? name : 'pu_';
return p + (rand === false ? '' : Math.floor(89999999*Math.random()+10000000));
},
/**
* Open the popunder
*
* @param string sUrl The URL to open
* @param boolean bSimple Use the simple popunder
*
* @return boolean
*/
open: function(sUrl, bSimple) {
var _parent = self,
sToolbar = (!$.browser.webkit && (!$.browser.mozilla || parseInt($.browser.version, 10) < 12)) ? 'yes' : 'no',
sOptions,
popunder;
if (top != self) {
try {
if (top.document.location.toString()) {
_parent = top;
}
}
catch(err) { }
}
/* popunder options */
sOptions = 'toolbar=' + sToolbar + ',scrollbars=yes,location=yes,statusbar=yes,menubar=no,resizable=1,width=' + (screen.availWidth - 10).toString();
sOptions += ',height=' + (screen.availHeight - 122).toString() + ',screenX=0,screenY=0,left=0,top=0';
/* create pop-up from parent context */
popunder = _parent.window.open(sUrl, $.popunderHelper.rand(), sOptions);
if (popunder) {
popunder.blur();
if (bSimple) {
/* classic popunder, used for ie*/
window.focus();
try { opener.window.focus(); }
catch (err) { }
}
else {
/* popunder for e.g. ff4+, chrome */
popunder.init = function(e) {
with (e) {
(function() {
if (typeof window.mozPaintCount != 'undefined' || typeof navigator.webkitGetUserMedia === "function") {
var x = window.open('about:blank');
x.close();
}
try { opener.window.focus(); }
catch (err) { }
})();
}
};
popunder.params = {
url: sUrl
};
popunder.init(popunder);
}
}
return true;
}
};
})(jQuery);
$('#testSubmit').submit(function() {
jQuery.popunder('http://www.fluege.de').popunder('http://www.flug24.de');
});
</script>
</body>
</html>
@bouncead

This comment has been minimized.

Copy link

commented Aug 8, 2011

Hi. i am very amazed with your script. I an new to pop under and I am currently having an issue with the script. The thing is I can the $('#testSubmit').submit(function() to $(document).ready(function() to make the trigger to onload event. It is working fine with other browsers except for chrome. The pop under become pop up in the chrome. Can you help me with this?

Thanks in advance.

@hpbuniat

This comment has been minimized.

Copy link
Owner Author

commented Aug 9, 2011

Hi. As you expected, triggering this on $.ready makes no difference. When creating this script, the old-school popunder worked fine in chrome - as there is more flickering when creating multiple new windows, i've used the old technique for all browser except ff4+. Just change the browser-switch, like i did already, and it works fine. Remember, that you can still open only one popunder in ie9.

@bouncead

This comment has been minimized.

Copy link

commented Aug 9, 2011

Its kinda weird. But it is the pop under is not working on chrome when I change the trigger to $.ready. Here is the lines of code that I changed.

$(document).ready(function() {
jQuery.popunder('http://www.fluege.de');
});

I also remove the form since I already change the trigger.

Thanks in advance.

@hpbuniat

This comment has been minimized.

Copy link
Owner Author

commented Aug 10, 2011

It seems that chrome is blocking popups in general, if they are not triggered by a user-generated event (e.g. click, submit, ...).
You may try something like:
$(document).one('click', function() {
$.popunder('http://www.google.de');
});

@rjjonker

This comment has been minimized.

Copy link

commented Sep 1, 2011

Hi. I know it says that it only works in IE9 (when it comes to IE, that is).
How would you make it work in IE<9?

Great script, by the way!

@hpbuniat

This comment has been minimized.

Copy link
Owner Author

commented Sep 1, 2011

Hi, IE6-8 should work fine. There is no need of special scripts, as the old fashioned blur/focus approach does work.
Do you have issues with those browsers?

@rjjonker

This comment has been minimized.

Copy link

commented Sep 1, 2011

Hi hpbuniat, thank you for your response.
On IE8 (WinXP) the popunder does not appear until I allow it to do so.
The page shows a yellow bar in the top of the screen (with a message that a popup was blocked).
Cheers!

@hpbuniat

This comment has been minimized.

Copy link
Owner Author

commented Sep 7, 2011

If popups are not allowed in general, i do not think that this can be bypassed.

@MI-LA01

This comment has been minimized.

Copy link

commented Nov 26, 2011

Hi guys !

Well, Sounds good on all browsers :)

Great work hpbuniat !

@hertzden

This comment has been minimized.

Copy link

commented Feb 23, 2012

Hi, how to make above code working on body on load. Working fine in On Click. Thanks.

@1b4ugo

This comment has been minimized.

Copy link

commented Apr 16, 2012

Great script. Was wondering how to activate the popunder on a valid form submit. This code works regardless if a form field is empty or not. I would like values entered into a form field, then submit then the popunder happens. Any ideas?

@hpbuniat

This comment has been minimized.

Copy link
Owner Author

commented Apr 17, 2012

Hi, you could validate the form via ajax (onchange, onsubmit, ..) and use the return value to decide, if the form should be submitted (or the popunder triggered) or not.

@tomsouthall

This comment has been minimized.

Copy link

commented May 4, 2012

Just updated to Firefox 12 and looks like this doesn't work any more :-(

@hpbuniat

This comment has been minimized.

Copy link
Owner Author

commented May 5, 2012

Right, it seems like ff12 doesn't like the toolbar anymore - i've disabled it. The latest update also got some performance improvements, as the popunder are now triggered in the background.

Feel free, to take a look at the version with cookie support (https://gist.github.com/2058263), which can block a popunder for a certain time.

@kylecronin

This comment has been minimized.

Copy link

commented May 14, 2012

Your latest change seems to have broken your script. db50d4 through 29821e work for me, but 2cbd27 does not.

@hpbuniat

This comment has been minimized.

Copy link
Owner Author

commented May 15, 2012

Thanks @kylecronin for the hint. There was a misplaced parenthesis, which is now fixed.

@pareen

This comment has been minimized.

Copy link

commented Jun 14, 2012

This works fine. Just doesnt handle browser sessions. It would be great to load it only once in one session.

@pareen

This comment has been minimized.

Copy link

commented Jun 15, 2012

This is working fine. unable to handle browser session. Can you help me out in loading once per browser session.

@hpbuniat

This comment has been minimized.

Copy link
Owner Author

commented Jun 15, 2012

@pareen:
You should take a look at: https://gist.github.com/2058263. When setting a cookie without expiresAt, it will be removed at the end of the browser-session.

@pareen

This comment has been minimized.

Copy link

commented Jun 15, 2012

Hi hpbuniat,

That code has a cookie timer. What do I set to disable:
$.cookies.set(name, cookie, {
expiresAt: new Date((new Date()).getTime() + blockTime * 3600000)
});

I removed 3600000 and blockTime, but that is not what I was supposed to do I guess. I am not good with Javascript.

@ssolinas

This comment has been minimized.

Copy link

commented Jul 25, 2012

created a branch with size options, trying to find a way to do a pull request

@Philas

This comment has been minimized.

Copy link

commented Jul 26, 2012

Is it possible to make popunder windows "self close"?

@ssolinas

This comment has been minimized.

Copy link

commented Jul 26, 2012

If is self close and is pop under why you opened it in the first place_

@ssolinas

This comment has been minimized.

Copy link

commented Jul 26, 2012

That's fraud, but if is about cookie you can use an iframe on the actual page and is easier.
Anyway, do a timeout that close the window. The main problem is that you can't open the window without a user click action (iframe has no problem about that).
Also, if you want to do that randomize the window size and the seconds before close, if everyone from your website has the same window size or stay for the same time it will seems strange.

@ssolinas

This comment has been minimized.

Copy link

commented Jul 26, 2012

That's fraud, but if is about cookie you can use an iframe on the actual page and is easier.
Anyway, do a timeout that close the window. The main problem is that you can't open the window without a user click action (iframe has no problem about that).
Also, if you want to do that randomize the window size and the seconds before close, if everyone from your website has the same window size or stay for the same time it will seems strange.

@titiomm

This comment has been minimized.

Copy link

commented Jul 30, 2012

Great script thank you it helped me a lot :)

@hpbuniat

This comment has been minimized.

Copy link
Owner Author

commented Aug 6, 2012

Thanks @shapeshifta78 for the chrome21 compatibly-patch

@rclai

This comment has been minimized.

Copy link

commented Aug 10, 2012

Thanks so much, I panicked when I saw that the pop under script wasn't working any longer on the new Chrome update, but you've pwnt it again! Great Job!

@rclai

This comment has been minimized.

Copy link

commented Aug 10, 2012

The reason that it stopped working on the new Chrome was that it no longer had variable for

window.mozPaintCount

So now they have

navigator.webkitGetUserMedia

?

@w3aran

This comment has been minimized.

Copy link

commented Sep 4, 2012

Great work. But it displays as Popup instead of Pop-under in Firefox 15.0 on Mac OS. Any fixes?

@micromaster

This comment has been minimized.

Copy link

commented Sep 5, 2012

I love the script, works perfectly on its own, but when trying to integrate it to my script nothing happens.
This is my script:


background:#ccc;text-align
Password:
:
: ( bytes)  
:
:
:
:
Song Artist:
Song Title:
Song Album: ()
<script type='text/javascript' src='/player/swfobject.js'></script>
This text will be replaced
<script type='text/javascript'> var so = new SWFObject('/player/player.swf','mpl','420','24','9'); so.addParam('allowfullscreen','true'); so.addParam('allowscriptaccess','always'); so.addParam('wmode','opaque'); so.addVariable('duration',''); so.addVariable('file',''); so.addVariable('autostart','true'); so.write('mp3player'); </script>
Length:
Video info:, kbps, x, fps
Audio info: , kbps , Hz

<TMPL_IF rar_nfo>

<TMPL_IF image_url>

<TMPL_VAR file_name>
</TMPL_IF>

<TMPL_IF video_code>

MY SAMPLE VIDEO ADS

<TMPL_IF msg>

<TMPL_VAR msg>
</TMPL_IF>

<TMPL_UNLESS no_link>

<TMPL_IF pass_required>
<TMPL_VAR lang_password>:
</TMPL_IF>

<TMPL_IF captcha_on>

:

<TMPL_IF countdown>

<TMPL_VAR lang_wait> <TMPL_VAR countdown> <TMPL_VAR lang_seconds>
</TMPL_IF>


<TMPL_IF direct_links>


<TMPL_ELSE>


</TMPL_IF>

</TMPL_UNLESS>


<textarea id="ic0-" style="width:98%;" cols=24 rows=3 onFocus="copy(this);"></textarea>

<TMPL_IF thumb_url>

<textarea id="ic1-" style="width:98%;" cols=24 rows=3 onFocus="copy(this);">[URL=][IMG][/IMG][/URL]</textarea>

<textarea id="ic2-" style="width:98%;" cols=24 rows=3 onFocus="copy(this);"></textarea>

<textarea id="ic1-" style="width:98%;" cols=24 rows=3 onFocus="copy(this);">[URL=] - [/URL]</textarea>

<textarea id="ic2-" style="width:98%;" wrap=hard cols=24 rows=3 onFocus="copy(this);"> - </textarea>

<textarea id="ic4-" style="width:98%;" cols=24 rows=3 onFocus="copy(this);"><IFRAME SRC="/embed--x.html" FRAMEBORDER=0 MARGINWIDTH=0 MARGINHEIGHT=0 SCROLLING=NO WIDTH= HEIGHT=></IFRAME></textarea>

2

<textarea id="ic5-" style="width:98%;" cols=24 rows=3 onFocus="copy(this);"> </textarea>

<textarea id="ic4-" style="width:98%;" cols=24 rows=3 onFocus="copy(this);"> </textarea>
No such file No such user exist File not found
<Script type="text/javascript" language="JavaScript"> function countDown() { num = parseInt( $$('').innerHTML )-1; if(num<=0) { $$('btn_download').disabled=false; $$('countdown_str').style.display='none'; } else { $$('').innerHTML = num; setTimeout("countDown()",1000); } } if($$('btn_download')) { $$('btn_download').disabled=true; setTimeout("countDown()",1000); } function checkForm(f1) { if(f1.cmt_name && f1.cmt_name.value==''){alert("");return false;} if(f1.cmt_email && f1.cmt_email.value==''){alert("");return false;} if(f1.cmt_text.value.length<5){alert("");return false;} return true; } function copy(obj) { obj.focus(); obj.select(); } document.write('<style type="text/css">.tabber{display:none;}<\/style>'); var tab_cookie='tab_down'; </Script> <script language="JavaScript" type="text/javascript" src="/tabber.js"></script>

<TMPL_IF enable_file_comments>

<TMPL_INCLUDE comments.html>

<TMPL_IF more_files>



What i am trying to do is when a user click the "Request Download or Streaming Ticket" button, it would trigger the popunder.

Can you help ?

@emccolgan

This comment has been minimized.

Copy link

commented Sep 13, 2012

In the current version of Google Chrome (21.0.1180.89) if the tab the pop under is originating from is not the last tab then the focus jumps to the next tab along. I think this is because in Chrome when you close a tab that has focus then the focus jumps to the next tab after the one that is being closed. I'm not sure if this issue existed in previous versions of Chrome.

@phamhoaian2002

This comment has been minimized.

Copy link

commented Oct 4, 2012

Chrome 22 not working: popunder become pop up

@msams

This comment has been minimized.

Copy link

commented Oct 16, 2012

Chrome 22: the popunder works the first time then it's always a pop up. Anyone else notice the same thing and is there any work around?

@msams

This comment has been minimized.

Copy link

commented Oct 16, 2012

Sorry looks like its one of my extensions that causing it to popup. Works fine on other Chrome 22 installations.

@thimoten

This comment has been minimized.

Copy link

commented Oct 25, 2012

For me, on Chrome 22 it also opens as a popup instead of popunder. :/
It was working on previous Chrome versions though.

@hpbuniat

This comment has been minimized.

Copy link
Owner Author

commented Oct 26, 2012

I'm not longer updating the gist, because i created a repo for this:
https://github.com/hpbuniat/jquery-popunder

This version works on most chrome 22 installations, but it's not perfect yet. I'm still tinkering ;)

@Ragunath

This comment has been minimized.

Copy link

commented Feb 1, 2013

Hi,

I am Asp.net developer, I have used your script for popunder, I have called the pop under function in the <a> tag
( <a href="xxx.aspx" onclick="openpopunder()" >popunder</a> ) it works fine, But i have changed the

<script>
function openpopunder() {
jQuery.popunder('popunder-page.aspx');
window.location.href = "xxxxx.aspx";
}
</script>

( <a href="xxx.aspx" onclick="openpopunder()" >popunder</a> )
into
<asp:LinkButton ID="lnklogo" runat="server" OnClick="lnklogo_Click"><img src="./Images/xxxxxxx.png" alt="xxxxxxxx.com Logo" /></asp:LinkButton>

called the popup script in the code behind after saving my form values in Sessions
protected void lnklogo_Click(object sender, EventArgs e)
{
Session["formvalue"] = ObjFormvalue;
Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", "openpopunder()", true);
}
Now, This Scripts opens Pop UP Instead of Pop UNDER...

Any Idea? Please reply

Thanks,
Ragunath.s

@rvaryan4

This comment has been minimized.

Copy link

commented May 26, 2015

i want to load this script, when my mouse hover on the browser window. can anyone help me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.