javascript实现浏览器窗口传递参数的方法
a.html
<html> <head> <title>主页面</title> <scriptlanguage="javascript"type="text/javascript"> functionOpenNew() { varim=newIDAndMethod(); im.ID=document.getElementById("txtID").value; window.showModalDialog("ddd.html",im,""); } functionIDAndMethod() { this.ID="ddd"; this.Method=SetTxt; } functionSetTxt(str) { document.getElementById("txtID").value=str; } </script> </head> <body> <formaction="#"> <inputid="txtID"style="width:400px"type="text"value="XXX!在这里输入ID!"/><br/> <inputtype="button"value="打开新的窗口"onclick="OpenNew()"/> </form> </body> </html>
b.html
<html> <head> <title>主页面</title> <scriptlanguage="javascript"type="text/javascript"> varim; functionLoad() { im=window.dialogArguments; if(im.ID=="XXX!在这里输入ID") document.getElementById("txtID1").value="你杂不输入呢!"; else document.getElementById("txtID1").value=im.ID; } functionSet() { im.Method(document.getElementById("txtID1").value); } </script> </head> <bodyonload="Load()"> <formaction="#"> <inputid="txtID1"style="width:400px"type="text"value="ddd"/><br/> <inputtype="button"value="传递数据"onclick="Set()"/> </form> </body> </html>