父页给iframe传参数的方法

来源:互联网 发布:苏州中学 知乎 编辑:程序博客网 时间:2024/05/17 23:56

我们开发当中会遇到一些需要使用iframe的时候,一般的写法是:

<iframe name="enventApplyIframe" id="enventApplyIframe" marginheight="0" marginwidth="0" frameborder="0" height="0" width="0" scrolling="no"  src="eventInsurealarmAction.jsp"></iframe>

但有时头疼的是包含这个iframe的父页需要控制它,如父页里有查询条件区,而显示页在iframe里。这是就会出现怎么把这些条件给iframe里并且运行的问题。

为了容易理解直接直接写一个例子吧。

<html><head><meta http-equiv="Content-Type" content="text/html; charset=euc-kr" /><title>iframe</title></head><body><form id="form1" name="form1" method="post" action="">  sex:<input name="sex" type="text" id="sex" size="15" />  age:<input name="age" type="text" id="age" size="15" />  <input type="button" name="Submit" value="button" onclick="javascript:goIframe();" /></form><iframe name="result" id="result" marginheight="0" marginwidth="0" frameborder="0" height="500" width="500" scrolling="no"  src="result.jsp"></iframe></body></html><script language="javascript">function goIframe(){var form = document.form1;var sex = form.sex.value;var age = form.age.value;var ifr = document.all("result");window.result.location.href=ifr.src +"?sex=" + sex + "&age=" + age;//window.result.location.href=search.do +"?sex=" + sex + "&age=" + age;}</script>
我想这段代码就不用解释了。
原创粉丝点击