阻止html頁面載入的方法,阻止html頁面

來源:互聯網
上載者:User

阻止html頁面載入的方法,阻止html頁面

在<body>標籤前加一個

<script type="text/javascript">document.execCommand("stop")</script>

即可阻止介面繼續載入


怎寫javascript代碼 阻止關閉網頁

onbeforeunload方法

onbeforeunload與onunload事件
Onunload,onbeforeunload都是在重新整理或關閉時調用,可以在<script>指令碼中通過window.onunload來指定或者在<body>裡指定。區別在於onbeforeunload在onunload之前執行,它還可以阻止onunload的執行。
Onbeforeunload也是在頁面重新整理或關閉時調用,Onbeforeunload是正要去伺服器讀取新的頁面時調用,此時還沒開始讀取;而onunload則已經從伺服器上讀到了需要載入的新的頁面,在即將替換掉當前頁面時調用。Onunload是無法阻止頁面的更新和關閉的。而 Onbeforeunload 可以做到。

頁面載入時只執行onload
頁面關閉時先執行onbeforeunload,最後onunload
頁面重新整理時先執行onbeforeunload,然後onunload,最後onload。

1、onbeforeunload事件:
說明:目前三大主流瀏覽器中firefox和IE都支援onbeforeunload事件,opera尚未支援。
用法:
·object.onbeforeunload = handler
·<element onbeforeunload = “handler” … ></element>
描述:
事件觸發的時候彈出一個有確定和取消的對話方塊,確定則離開頁面,取消則繼續待在本頁。handler可以設一個傳回值作為該對話方塊的顯示文本。

觸發於:
·關閉瀏覽器視窗
·通過地址欄或收藏夾前往其他頁面的時候
·點擊返回,前進,重新整理,首頁其中一個的時候
·點擊 一個前往其他頁面的url串連的時候
·調用以下任意一個事件的時候:click,document write,document open,document close,window close ,window navigate ,window NavigateAndFind,location replace,location reload,form submit.
·當用window open開啟一個頁面,並把本頁的window的名字傳給要開啟的頁面的時候。
·重新賦予location.href的值的時候。
·通過input type=”submit”按鈕提交一個具有指定action的表單的時候。
可以用在以下元素:
·BODY, FRAMESET, window
平台支援:
IE4+/Win, Mozilla 1.7a+, Netscape 7.2+, Firefox0.9+
樣本:
<html xmlns="www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title&......餘下全文>>
 
怎屏蔽HTML中所調用模組的CSS

1、首先找到該模組的css檔案。
2、找到你要修改的部分所調用的class名或者id。
3、在當前html頁面將要修改的部分的class名或者id重新定義樣式。

比如:
當前頁面中調用了某個css檔案,這個css檔案是用於那個模組的預設css檔案。

<head>
<title>change css</title>
<link rel="stylesheet" rev="stylesheet" href="css/normal.css" type="text/css" media="all" />
</head>

在這個normal.css裡有個class的樣式定義為:

lookme {width: 300px; height: 10px; background:#ccc;}

現在如果你想要讓他在當前頁面有所改變,你就直接在當前頁面內重新定義lookme,比如:

<head>
<title>change css</title>
<link rel="stylesheet" rev="stylesheet" href="css/normal.css" type="text/css" media="all" />
</head>
<style type="text/css">
lookme {width: 100px; height: 50px; background:red;}
</style>

這樣就可以了。最後顯示結果會以當前頁面為準。
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.