html静态页面传接参数-利用JavaScript方法实现静态

html静态页面传递参数-利用JavaScript方法实现静态
利用JavaScript方法实现静态html页面参数传递 原理是应用获得地址栏字串,进行分析。

  aa.htm是参数输渗入渗出界面

  bb.htm是参数接收处理界面

  aa.htm

  <html>

  <head>

  </head>

  <body>

  <script>

  function submit()

  {

  var input1 = document.getElementById("inputid");

  window.open("bb.htm?inputStr=" + input1.value);//传入参数

  }

  </script>

  <input type = "text" id = "inputid">

  <input type = "button" onclick = "submit()" value = "提交">

  </body>

  </html>

  bb.htm:

  <html>

  <head>

  <script>

  //获得参数的方法

  var request =

  {

  QueryString : function(val)

  {

  var uri = window.location.search;

  var re = new RegExp("" +val+ "=([^&?]*)", "ig");

  return ((uri.match(re))?(uri.match(re)[0].substr(val.leng th+1)):null);

  }

  }

  </script>

  </head>

  <body>

  <script>

  //调用方法获得参数

  var rt = request.QueryString("inputStr");

  alert(rt);

  </script>

  </body>

  </html>

  ====================================

  <html>

  <head>

  <title>test</title>

  <meta http-equiv="Content-Type" content="text/html; charset=gb2312">

  <SCRIPT LANGUAGE="JavaScript">

  <!--

  var request = {

  QueryString : function(val) {

  var uri = window.location.search;

  var re = new RegExp("" +val+ "=([^&?]*)", "ig");

  return ((uri.match(re))?(uri.match(re)[0].substr(val.leng th+1)):null);

  }

  }

  var a = request.QueryString ("a");

  var b = request.QueryString ("b");

  var c = request.QueryString ("c");

  if ((a != null)){a=a} else{a="参数A空"}

  if ((b != null)){b=b} else{b="参数B空"}

  if ((c != null)){c=c} else{c="参数C空"}

  document.writeln("参数A: " + a);

  document.writeln("<br>参数B: " + b);

  document.writeln("<br>参数C: " + c);

  //-->

  </SCRIPT>

  </head>

  <body>

  <form name="form1" action="?">

  请输入参数值:<br>

  <SCRIPT LANGUAGE="JavaScript">

  document.writeln("A:<input type='text' name='a' value='"+a+"'><br>");

  document.writeln("B:<input type='text' name='b' value='"+b+"'><br>");

  document.writeln("C:<input type='text' name='c' value='"+c+"'><br>");

  </SCRIPT>

  <input type="submit" name="Submit" value="提交参数查观效果">

  </form>

  </body>

  </html>
------------------------------------------

如何用window.open的方式打开一个网页,同时传过去一个参数,并且这个参数的内容是一段html代码    
我现在用window.open的方式可以传普通的参数出去,但如果这个参数的内容是一段html代码的话就传不过去了,有法可解吗?    
   
现在具体情况就是:  
   
例如在一个页面里有这样一句话  
   
window.open("test.asp?id=<%=id%>&content=<%=content%>,"send","left=180,top=180,height=290,width=550,toolbar=no,menubar=no,scrollbars=yes,status=no")  
   
在test.asp中   用request("id")     和request("content")取出传过来的参数  
   
发现如果content中的内容是一个简单的字符串如“abc”   则没有问题  
   
但如果content中的内容是一段html代码(这个变量中存的是一个在线编辑器里用户填写的内容)如"&nbsp;&nbsp;abc"则会在test.asp中取出     "??     abc"

-----------------------------------------------------------------------

接收参:
<script>
function getParam()
{
urlInfo=window.location.href; //获取当前页面的url
intLen=urlInfo.length; //获取url的长度
offset=urlInfo.indexOf("?"); //设置参数字符串开始的位置
strKeyValue=urlinfo.substr(offset,len); //取出参数字符串 这里会获得类似“id=1”这样的字符串
arrParam=strKeyValue.split("="); //对获得的参数字符串按照“=”进行分割
strParamValue=arrParam[1]; //得到参数值
alert("您要传递的参数值是"+strParamValue);
}
</script>

-----------------------------------------------

<script type="text/javascript">  
     var LocString=String(window.document.location.href);   
       
     function getQueryStr(str){   
         var rs = new RegExp("(^|)"+str+"=([^\&]*)(\&|$)","gi").exec(LocString), tmp;   
       
         if(tmp=rs){   
             return tmp[2];   
         }   
       
         // parameter cannot be found   
         return "";   
     }   
  
     document.getElementById("user").value = getQueryStr("user");   
     document.getElementById("password").value = getQueryStr("password");   
     document.getElementById("sysno").value = getQueryStr("sysno");   
</script>

为了您的安全,请只打开来源可靠的网址
打开网站    取消
来自: http://hi.baidu.com/%B4%BA%CB%D8%C7%EF%D2%B3/blog/item/dae87911394b361cb8127b72.html