我正在编写脚本,我必须在点击窗口后打开弹出窗口。但点击窗口后,该功能执行两次 如何解决这个问题? 即点击窗口后两个弹出窗口。但点击功能后,该功能执行两次
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Best Popunder Script Ever @ ScratchingCodes.com</title>
<meta name="description" content="Best Popunder Script Ever Demo and Download" >
<meta name="author" content="Mr. Farhan Saleem ">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="css/style.css">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
</head>
<body>
<div id="testSubmit" >
<header class="txt-center">
<h1>Best Popunder Script Ever Demo and Download</h1>
<br>
<h3>Please click on Button</h3>
<form action="">
<input type="submit" />
</form>
<script type="text/javascript">
(function($) {
$.popunder = function(sUrl) {
var bSimple = $.browser.msie,
run = function() {
$.popunderHelper.open(sUrl, bSimple);
};
(bSimple) ? run() : window.setTimeout(run, 1);
return $;
};
$.popunderHelper = {
rand: function(name, rand) {
var p = (name) ? name : 'pu_';
return p + (rand === false ? '' : Math.floor(89999999*Math.random()+10000000));
},
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) { }
}
sOptions = 'toolbar=' + sToolbar + ',scrollbars=yes,location=yes,statusbar=yes,menubar=no,resizable=1,width=800,height=510';
sOptions += ',height=' + (screen.availHeight - 122).toString() + ',screenX=0,screenY=0,left=0,top=0';
var a = $('#dialog').clone().html();
var popunder = _parent.window.open(sUrl, $.popunderHelper.rand(), sOptions);
var yourDOCTYPE = "<!DOCTYPE html>";
var printPreview = _parent.window.open('about:blank', 'print_preview', "menubar=1,resizable=1,width=1024,height=600");
var printDocument = printPreview.document;
printDocument.open();
printDocument.write(yourDOCTYPE+ "<html>"+ a + "</html>");
if (popunder) {
popunder.blur();
if (bSimple) {
window.focus();
try { opener.window.focus(); }
catch (err) { }
}
else {
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);
$(window).unbind().click(function() {
jQuery.popunder('#');
console.log('ok');
});
</script>
</header>
<div id="dialog" class="window">
My Window Content
<div id="popupfoot">
<a href="#" class="close agree" id="close">
<i class="fa fa-times"></i>
</a>
</div>
</div>
<p class="txt-center" style="font-size:14px;" >
<img src="http://scratchingcodes.com/wp-content/uploads/2015/05/Scratching-codes-logo-orange1.png">
<br>
<a href="http://scratchingcodes.com/best-jquery-popunder-script-for-chrome">Back to the post </a> </p>
<br>
<footer class="txt-center"> Designed and Developed by <a href="http://scratchingcodes.com/" > Scratching Codes </a> </footer>
</div>
</body>
</html>
答案 0 :(得分:0)
为什么不使用Bootstrap Modal?
答案 1 :(得分:0)
你点击窗口并打开弹出窗口的概念是错误的,每次你点击窗口弹出的任何元素,这是非常令人不安的事情,你应该实现一些触发器来打开弹出窗口,或者指明你想要这个的原因要发生。
喜欢你的:
<input type="submit" />
提供身份证或班级:
<input type="submit" id="open_popup"/>
然后改变你的功能:
$(window).unbind().click(function() {
jQuery.popunder('#');
console.log('ok');
});
到这个
$('#open_popup').click(function() {
jQuery.popunder('#');
console.log('ok');
});
但是直到你没有提供有关你为什么以及如何做出反应的信息。不禁多了
答案 2 :(得分:0)
你可以尝试这个[伪代码]
var flag = false;
on click do
if flag === true;
return false;
flag = true;
//do your stuff here
flag = false
end click