Javascript Pop-Under:每个会话和Onload仅一次
我正在谷歌上搜索,但找不到好的解决方案。我在脚本下搜索一个弹出窗口,它打开一个新的url窗口,但每次只能搜索一次。我发现了很多脚本,但打开了一个新的窗口,只为onclick 函数jspopurl,sConfig{ sConfig=sConfig | |{}; var sName=sConfig.name | | Math.floorMath.random*1000+1; var sWidth=sConfig.width | | window.innerWidth; var sHeight=sConfig.height | | window.innerHeight; var sPosX=typeofsConfig.left!=“未定义”?sConfig.left.toString:window.screenX; var sPosY=typeofsConfig.top!=“未定义”?sConfig.top.toString:window.screenY; /*封顶*/ var sWait=sConfig.wait | | 3600;sWait=sWait*1000; var sCap=sConfig.cap | | 2; /*饼干*/ var popsToday=0; var cookie=sConfig.cookie | |'uuu.popunder'; 变量浏览器=函数{ var n=navigator.userAgent.toLowerCase; 变量b={ webkit:/webkit/.testn, mozilla:/mozilla/.testn&!/compatible | webkit/.testn, chrome:/chrome/.testn, msie:/msie/.testn&!/opera/.testn, firefox:/firefox/.testn, safari:/safari/.testn&!/chrome/.testn, opera:/opera/.testn }; b、 version=b.safari?n.match/+?:ri[\/:][\d.]+/| |[[1]:n.match/+?:ox | me | ra | ie[\/:][\d.]+/|[[1]; 返回b; }; 函数是有上限的{ 试一试{ popsToday=Math.floordocument.cookie.splitcookie+'Cap='[1]。split';'[0]; }catcherr{}Javascript Pop-Under:每个会话和Onload仅一次,javascript,popup,Javascript,Popup,我正在谷歌上搜索,但找不到好的解决方案。我在脚本下搜索一个弹出窗口,它打开一个新的url窗口,但每次只能搜索一次。我发现了很多脚本,但打开了一个新的窗口,只为onclick 函数jspopurl,sConfig{ sConfig=sConfig | |{}; var sName=sConfig.name | | Math.floorMath.random*1000+1; var sWidth=sConfig.width | | window.innerWidth; var sHeight=sC
return sCap我设法修改了我在网上找到的一个与您类似的代码示例,以便在“文档加载”下自动打开一个Pop。需要结合jQuery来实现它,但是我删除了cookies代码段,因此每次会话一次的操作将不起作用 代码如下:
function makePopunder(pUrl) {
var _parent = (top != self && typeof (top["document"]["location"].toString()) === "string") ? top : self;
var mypopunder = null;
var pName = (Math["floor"]((Math["random"]() * 1000) + 1));
var pWidth = window["innerWidth"];
var pHeight = window["innerHeight"];
var pPosX = window["screenX"];
var pPosY = window["screenY"];
var pWait = 3600;
pWait = (pWait * 1000);
var pCap = 50000;
var todayPops = 0;
var cookie = "_.mypopunder";
var browser = function () {
var n = navigator["userAgent"]["toLowerCase"]();
var b = {
webkit: /webkit/ ["test"](n),
mozilla: (/mozilla/ ["test"](n)) && (!/(compatible|webkit)/ ["test"](n)),
chrome: /chrome/ ["test"](n),
msie: (/msie/ ["test"](n)) && (!/opera/ ["test"](n)),
firefox: /firefox/ ["test"](n),
safari: (/safari/ ["test"](n) && !(/chrome/ ["test"](n))),
opera: /opera/ ["test"](n)
};
b["version"] = (b["safari"]) ? (n["match"](/.+(?:ri)[\\/: ]([\\d.]+)/) || [])[1] : (n["match"](/.+(?:ox|me|ra|ie)[\\/: ]([\\d.]+)/) || [])[1];
return b;
}();
function doPopunder(pUrl, pName, pWidth, pHeight, pPosX, pPosY) {
var sOptions = "toolbar=no,scrollbars=yes,location=yes,statusbar=yes,menubar=no,resizable=1,width=" + pWidth.toString() + ",height=" + pHeight.toString() + ",screenX=" + pPosX + ",screenY=" + pPosY;
$( document ).ready(function (e) {
window["pop_clicked"] = 1;
mypopunder = _parent["window"]["open"](pUrl, pName, sOptions);
if (mypopunder) {
pop2under();
}
});
};
function pop2under() {
try {
mypopunder["blur"]();
mypopunder["opener"]["window"]["focus"]();
window["self"]["window"]["blur"]();
window["focus"]();
if (browser["firefox"]) {
openCloseWindow();
};
if (browser["webkit"]) {
openCloseTab();
};
} catch (e) {};
};
function openCloseWindow() {
var ghost = window["open"]("about:blank");
ghost["focus"]();
ghost["close"]();
};
function openCloseTab() {
var ghost = document["createElement"]("a");
ghost["href"] = "about:blank";
ghost["target"] = "PopHelper";
document["getElementsByTagName"]("body")[0]["appendChild"](ghost);
ghost["parentNode"]["removeChild"](ghost);
var clk = document["createEvent"]("MouseEvents");
clk["initMouseEvent"]("click", true, true, window, 0, 0, 0, 0, 0, true, false, false, true, 0, null);
ghost["dispatchEvent"](clk);
window["open"]("about:blank", "PopHelper")["close"]();
};
function pop_isRightButtonClicked(e) {
var rightclick = false;
e = e || window["event"];
if (e["which"]) {
rightclick = (e["which"] == 3);
} else {
if (e["button"]) {
rightclick = (e["button"] == 2);
};
};
return rightclick;
};
doPopunder(pUrl, pName, pWidth, pHeight, pPosX, pPosY);}
注意我是如何在$document.readyfunction e{…}中使用jQuery的。这会在加载文档时触发事件
然后只需在html文档的主体中添加makePopunder;inside脚本标记
上面的原始脚本具有使用cookies的每会话一次功能,因此欢迎您使用我的修改对其进行编辑,并保留cookies的原始代码:
适用于所有桌面和移动浏览器:Firefox、Chrome、Safari等