1. 程式人生 > >IE下iframe不能正常載入,顯示空白

IE下iframe不能正常載入,顯示空白

下午幫忙看了一個web問題,index.html中嵌入<iframe>來載入同文件目錄下的一個頁面,在多個瀏覽器下測試,發現IE瀏覽器中會出現問題,<iframe>不能正常載入,顯示空白頁,右鍵屬性為"_blank"

一開始,想到的是src屬性的問題,可能是路徑不對,但是經過不同瀏覽器測試,不存在路徑問題。

單獨把src路徑拿出來,貼到IE瀏覽器中,發現頁面載入沒問題。通過分析,問題應該出現在index.html檔案中,單獨的<iframe>載入ok,通過排除法,就是Index.html檔案中某些程式碼出現了問題,使得IE瀏覽器發飆了。

然後,上網找尋答案,有很多很多的帖子在問相關問題,也有很多人開博寫這種問題的解決辦法,大概羅列如下:

       1.IE瀏覽器的bug<iframe>標籤的src屬性不要放到第一位,因為這樣會誘發IEbug.

      2.採用動態建立dom節點的方式,來建立<iframe>動態載入頁面。

後來經過大勇的測試發現,將index.html頁面頭部的<!--saved from url=(0022)http://www.yoururl.com -->程式碼去掉之後,頁面載入問題解決了,但是這行程式碼的作用何在?

這也是解決了本問題的一個方案,經過查閱資料,這行程式碼的用途是IE下安全驗證的一個設定,來控制是否會彈出黃色的訊息提示框,來提醒你是否允許此Active執行在客戶端。

	To allow active content or scripting to run in a web page without the 
	Information Bar appearing, you can add "Mark of the Web" code, 
	so that the file is run in a zone other than the Local Machine zone, 
	for example the Internet zone or the Intranet zone.
	 The following code is an example of a Mark of the Web: 
	
	<!-- saved from url=(0022)http://www.yoururl.com -->
	
	To include the code above in your projects, change the URL 
	to point to your domain, and change the number (0022) to the
	 correct number for your domain. This number indicates 
	how many characters are in your domain name (beginning with
	 the "h" in "http", and ending with the last letter of your domain;
	for example, the "m" in ".com"). 
	
	A generic way of writing the Mark of the Web code is as follows: 
	
	<!-- saved from url=(0014)about:internet -->
	
	about:internet will place the page in the Internet zone, 
	allowing the page to bypass the Local Machine zone lockdown. 

此程式碼是用來控制哪些使用者訪問時不會提示驗證提示框,而我們如何跳過這個設定,來執行我們的web專案呢?

我們可以遠端預覽頁面或者在本地部署iis/tomcat伺服器來執行專案,這樣就可以在IE下正常載入<iframe>頁面,並且不影響安全性驗證提醒。

參考: