自动加载弹出,不使用主体标签中的onload属性
automatic onload pop-up without using the onload attribute in body tag
你能给一些链接吗?当我谷歌所有的垃圾网站出现!
您可以对window
对象上的load
事件执行此操作:
DOM0)风格:
window.onload = function() {
alert("But please don't.");
};
或者使用DOM2方法:
if (window.addEventListener) { // DOM2 standard
window.addEventListener('load', handler, false);
}
else if (window.attachEvent) { // Fallback for older IE versions
window.attachEvent('onload', handler);
}
function handler() {
alert("But again, please don't.");
}
正如他们在http://pastie.org上所说,请使用这些信息在你的任务中拯救人类,而不是你的邪恶阴谋接管世界。
你是不想在body元素上使用onload属性,还是根本不想使用onload事件,这还不是很清楚。
T.J.克劳德的回答给出了一些使用事件监听器的好例子,这是最好的方法。
如果出于某种原因你根本不想使用onload事件,你可以在HTML标签的前面放一个script标签,里面有一个警告。但是在生产环境中你不应该这样做……它不会像body。onload。
我拿到代码了!
我正在复制粘贴工作的确切代码......
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js" type="text/javascript"></script>
<script src="http://dinhquanghuy.110mb.com/jquery.cookie.js" type="text/javascript"></script>
<script type="text/javascript">
var popupStatus = 0;
//loading popup with jQuery magic!
function loadPopup(){
centerPopup();
//loads popup only if it is disabled
if(popupStatus==0){
$("#backgroundPopup").css({
"opacity": "0.7"
});
$("#backgroundPopup").fadeIn("slow");
$("#popupContact").fadeIn("slow");
popupStatus = 1;
}
}
//disabling popup with jQuery magic!
function disablePopup(){
//disables popup only if it is enabled
if(popupStatus==1){
$("#backgroundPopup").fadeOut("slow");
$("#popupContact").fadeOut("slow");
popupStatus = 0;
}
}
//centering popup
function centerPopup(){
//request data for centering
var windowWidth = document.documentElement.clientWidth;
var windowHeight = document.documentElement.clientHeight;
var windowscrolltop = document.documentElement.scrollTop;
var windowscrollleft = document.documentElement.scrollLeft;
var popupHeight = $("#popupContact").height();
var popupWidth = $("#popupContact").width();
var toppos = windowHeight/2-popupHeight/2+windowscrolltop;
var leftpos = windowWidth/2-popupWidth/2+windowscrollleft;
//centering
$("#popupContact").css({
"position": "absolute",
"top": toppos,
"left": leftpos
});
//only need force for IE6
$("#backgroundPopup").css({
"height": windowHeight
});
}
//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
if ($.cookie("anewsletter") != 1) {
//load popup
setTimeout("loadPopup()",5000);
}
//CLOSING POPUP
//Click the x event!
$("#popupContactClose").click(function(){
disablePopup();
$.cookie("anewsletter", "1", { expires: 7 });
});
//Click out event!
$("#backgroundPopup").click(function(){
disablePopup();
$.cookie("anewsletter", "1", { expires: 7 });
});
//Press Escape event!
$(document).keypress(function(e){
if(e.keyCode==27 && popupStatus==1){
disablePopup();
$.cookie("anewsletter", "1", { expires: 7 });
}
});
});
</script>
相关文章:
- 在<页眉>标签
- Ckeditor-plugin:插入虚假元素add不情愿<p>标签前后
- 主体上的addEventListener('mousemove',..)-有多糟糕
- iframe正在添加标签,需要删除它们
- 如何自动调整标签的高度以适应内容
- Jquery标签插件粘贴问题
- Twitter引导程序Typeahead-Id&标签
- Highcharts-如何在自定义格式化程序中获得默认的y轴标签格式化程序
- Morris.js折线图x轴标签在调整大小后消失
- JavaScript goto 标签如何使用内部循环
- PhysicsJS - 如何通过标签(或其他值)查找主体
- 如何将程序创建的标签的文本分配给html主体中的其他标签
- 如何使网站主体标签内的内容完全可伸缩?
- 如何在iFrame主体标签上设置jQuery data()并从iFrame内部检索它
- 用javascript打开主体标签后插入Google标签管理器
- 在两个HTML文件之间交换主体标签
- Google Maps API's初始化函数,不带ONLOAD主体标签或在结束主体之前
- html标签和主体之间有奇怪的空白
- 自动加载弹出,不使用主体标签中的onload属性
- 如何从主体标签中删除onload事件