利用location.hash传递参数

JS跨域操作Dom http://www.iteye.com/problems/56264

http://www.chinaz.com/web/2011/1123/222158.shtml

a.html:

Html代码 复制代码 收藏代码
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3.  <head>  
  4.   <title> new document </title>  
  5.     <SCRIPT LANGUAGE="JavaScript">  
  6.     <!--   
  7.         var src="";   
  8.         window.onload=function(){   
  9.             src=document.getElementById('ifrm_1').src;   
  10.         }   
  11.         function fn1(){   
  12.             var ifm=document.getElementById('ifrm_1'),ipt=document.getElementById('ipt');   
  13.             ifm.src=src+"#"+ipt.value;   
  14.         }   
  15.     //-->  
  16.     </SCRIPT>  
  17.  </head>  
  18.  <body>  
  19.     <input id="ipt" type="text" />  
  20.     <input type="button" value="test" onclick="fn1()"/><br/>  
  21.     <iframe id='ifrm_1' src='http://61b7.ipc.la/b.html'></iframe>  
  22.  </body>  
  23. </html>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title> new document </title>
	<SCRIPT LANGUAGE="JavaScript">
	<!--
		var src="";
		window.onload=function(){
			src=document.getElementById('ifrm_1').src;
		}
		function fn1(){
			var ifm=document.getElementById('ifrm_1'),ipt=document.getElementById('ipt');
			ifm.src=src+"#"+ipt.value;
		}
	//-->
	</SCRIPT>
 </head>
 <body>
	<input id="ipt" type="text" />
	<input type="button" value="test" onclick="fn1()"/><br/>
	<iframe id='ifrm_1' src='http://61b7.ipc.la/b.html'></iframe>
 </body>
</html>



b.html(http://61b7.ipc.la/b.html):

Html代码 复制代码 收藏代码
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3.  <head>  
  4.   <title> new document </title>  
  5.   <SCRIPT LANGUAGE="JavaScript">  
  6.   <!--   
  7.     window.onload=function(){   
  8.         var h=window.location.hash,s=document.getElementById('show'),ipt=document.getElementById('ipt');   
  9.         setInterval(function(){   
  10.             if(h!=window.location.hash){   
  11.                 h=window.location.hash;   
  12.                 ipt.value=h.replace('#','');   
  13.             }   
  14.         },100);   
  15.     }   
  16.   //-->  
  17.   </SCRIPT>  
  18.  </head>  
  19.  <body>  
  20.     <input id="ipt" type="text" />  
  21.     <div id="show"></div>  
  22.  </body>  
  23. </html>  
posted @ 2012-07-12 19:32  stma  阅读(2260)  评论(0)    收藏  举报