Created
June 12, 2011 19:44
-
-
Save hpbuniat/1021924 to your computer and use it in GitHub Desktop.
Test for a popunder working in ff 3-14, chrome 10-21, ie6-9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i want to load this script, when my mouse hover on the browser window. can anyone help me.