jsp佈局中關於標籤的使用

iframe 元素會創建包含另外一個文檔的內聯框架(即行內框架)。注意:在 HTML 4.1 Strict DTD 和 XHTML 1.0 Strict DTD 中,不支持 iframe 元素。

<div id="iframepage">
<iframe src="/test/common.html" align="middle" id="iframepage"  width="100%" height="435" frameborder="0" scrolling="no" marginheight="0" marginwidth="0"  ></iframe>
</div>

1.獲取iframe的自適應大小,即:不適用height和width屬性,而是用οnlοad="SetWinHeight(this);IFrameReSizeWidth(this)"方法

<script type="text/javascript">
function SetWinHeight(obj) 
{ 
	   var win=obj; 
	   if (document.getElementById("iframepage")) 
	   { 
		   if (win && !window.opera) 
		   { 
			   if (win.contentDocument && win.contentDocument.body.offsetHeight) {
				   win.height = win.contentDocument.body.offsetHeight + 25;
				   } 
			   else if(win.Document && win.Document.body.scrollHeight) {
				   win.height = win.Document.body.scrollHeight + 25;
			   } 
			   
		   } 
	   } 
} 

function IFrameReSizeWidth(obj) {
	   var win=obj; 
	   if (document.getElementById("iframepage"))
	   { 
		   if (win && !window.opera) 
		   { 
			   if (win.contentDocument && win.contentDocument.body.offsetWidth) {
				   win.width = win.contentDocument.body.offsetWidth;
				   } else if(win.Document && win.Document.body.scrollWidth) {
				   win.width = win.Document.body.scrollWidth;
			   } 
			   
		   } 
	}

}
</script>

2.在iframe頁面中用js操作父窗口的內容

window.parent.document.getElementById('mulufirst').innerHTML=$(this).text();


3.iframe中的鏈接在父窗口中不出現”畫中畫“,即如何操作它的類似於target的屬性:在location前加上window.top/parent/blank.....等,如果是單純的<a>標籤,直接設置target屬性即可;

<a class="search_btn"   id="searchAnswer">搜索答案</a>

<script>
	$(function() {
		var searchKey = $("#searchAsk");

		$("#searchAnswer")
				.click(
						function() {
							if (searchKey.val() == ""
									|| searchKey.val() == "請輸入你的問題?") {
								window.top.location.href = "http://baidu.com";
							} else {
								var asktitle = escape(searchKey.val());
								window.top.location.href = "http://hao123.com?key=121";
							}

						});
		
</script>

如果需要設成_blank屬性的話,不能直接用window.blank.location.href

window.top.location.href = "http://baidu.com";
window.open("http://baidu.com","_blank");



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章