您能否給一些鏈接?當我谷歌所有垃圾郵件站點出現!自動彈出而不使用主體標籤中的onload屬性
-1
A
回答
0
您可以用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說了,請使用這些信息來拯救人類,而不是你的邪惡陰謀接管世界。
0
您是否不想使用onload屬性,只是不在body元素上,或者根本不想使用onload事件,這並不十分清楚。
T.J. Crowders的答案爲使用事件監聽器提供了一些很好的例子,這是最好的方式。
如果由於某種原因您根本不想使用onload事件,那麼可以在標記之前的HTML中放置一個腳本標記,並在其中包含警報。你不應該這樣做,因爲生產中的任何東西,但它不會做與body.onload完全相同的東西...
0
我得到了代碼!
我複製粘貼工作,其確切的代碼......
<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>
相關問題
- 1. 何時使用屬性而不是Neo4j中的標籤?
- 2. TinyURL彈出開放而不是標籤
- 3. 如何用鼠標拖動Farseer物體,而不會彈性?
- 4. 移動dygraphs彈出標籤
- 5. 設置身體onload而不使用<body>標記
- 6. 如何使用彈簧窗體標籤訪問數組列表的屬性?
- 7. 在自定義JSTL庫中使用彈簧窗體標籤
- 8. 使用標籤和屬性
- 9. 使用標籤屬性
- 10. HTML標記img的屬性onload在Angular2中不起作用
- 11. 彈出式窗體不會自動提交 - 使用大型彈出式窗口
- 12. 標籤不使用自定義字體
- 13. 彈簧模型屬性2.0標籤
- 14. 使用simple_hashtag寶石模型的「身體」鏈接到主題標籤屬性
- 15. 是否使用彈簧窗體標籤?
- 16. 在樣式屬性(不是標籤,但屬性)中應用媒體查詢?
- 17. 如何啓動onLoad的彈出燈箱?
- 18. div標籤 - 浮動屬性
- 19. Magnific酒店中使用HTML彈出標題屬性
- 20. XMLHttpRequest onload屬性?
- 21. Ajax - onload屬性
- 22. 無法使用自定義標籤中的屬性jsp
- 23. 在輸入標籤上使用自動聚焦屬性時,不會調用onfocus
- 24. 不使用自定義標籤屬性如<a my_att='...'>
- 25. 使用主題標籤創建彈出式窗口效果
- 26. 使用prestashop的1.7 smarty url標籤中的動作屬性
- 27. 如何使用屬性值獲取Magento中的產品,而不是標籤
- 28. 自動點擊使用onload?
- 29. CSS屬性不適用於主體類
- 30. 使用DIV:標題標籤的屬性,而不是一個:href屬性切換的div
我很高興彈出窗口阻止程序阻止這些。 – epascarello 2011-05-03 14:51:29