`
CobWeb
  • 浏览: 39985 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
文章分类
社区版块
存档分类
最新评论

两个独立静态htm页面间如何传值

阅读更多
<script>
urlinfo=window.location.href; //获取当前页面的url
len=urlinfo.length;//获取url的长度
offset=urlinfo.indexOf("?");//设置参数字符串开始的位置
newsidinfo=urlinfo.substr(offset,len)//取出参数字符串 这里会获得类似“id=1”这样的字符串
newsids=newsidinfo.split("=");//对获得的参数字符串按照“=”进行分割
newsid=newsids[1];//得到参数值
alert("您要传递的参数值是"+newsid);
</script>
­
­
­
两个纯HTML页面间传值问题,纯用JS实现:  
  比如11.htm   和   22.htm。  
  目的:11.htm通过innerHTML生成页面,点击print的时候弹出22.htm页并将ss值传过去,22.htm得到ss的值并根据ss的值生成页面。22.htm全屏显示  
    
  条件:不能用XXX.htm?xxx=xxx的方式传递  
    
  11.htm  
    
  <html>  
  <head>  
  <title>11</title>  
  </head>  
  <body>  
  <input     type   =button   onclick   ='op();'   value='print'>  
  <div   id=show>  
  </div>  
  <script   language=javascript>  
  var   ss=   "<hr>This   is   test!<hr>"  
  document.all.show.innerHTML=ss;  
  function   op(){  
  window.open('22.htm','fff').focus();  
  }  
  </script>  
  </body>  
  </html>  
    
  22.htm  
    
  <html>  
  <head>  
  <title>22</title>  
  </head>  
  <body>  
  <script   language=javascript>  
  var   aa=     ----------------------------------11.htm传过来的ss的值  
  document.write(aa);  
  </script>  
  </body>  
  </html>  
  
­
­
­
第一个页面: a.html
<html>
<head>
</head>
<body>
<script language="javascript" type="text/javascript">
function Open()
{
window.open('b.html');
}
</script>
<form>
<input type="text" id="tbValue"><a href="#" onclick="Open()">Open http://www.dwww.cn </a>
</form>
</body>
</html>
第二个页面: b.html
<html>
<head>
</head>
<script language="javascript" type="text/javascript">
function SetValue(value)
{
self.opener.document.all("tbValue").value=value;
}
</script>
<body>
Values:<br/>
<a href="javascript:SetValue('1')">value 1</a><br/>
<a href="javascript:SetValue('2')">value 2</a>
</body>
</html>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics