Tom*_*Tom 7 html javascript forms iframe
我试图通过将值从一个传递到另一个来粘合两个Web服务,遗憾的是,没有API或明确的方式来破解搜索查询,因此我需要在iframe中设置输入的值.
这是可怕的iframe的标记.
<form id="searchForm" method="post" action="/search/initialSearch">
<fieldset class="searchFields">
<input type="text" name="searchTerm" value=""/>
<input type="submit" value="Find stops"/>
</fieldset>
</form>
Run Code Online (Sandbox Code Playgroud)
我需要设置searchTerm文本然后提交表单.
注意:这是移动的,所以我更喜欢一个非常轻量级的解决方案
不是这么简单:
myframe.document.getElementById("searchForm").searchTerm.value = 'hello';
myframe.document.getElementById("searchForm").submit();
Run Code Online (Sandbox Code Playgroud)
确保您的脚本在iframe
加载后运行.您的iframe
标记有一个onload
事件,您可以使用该事件来确定何时加载框架中的页面.
<iframe src="formPage.html" onload="loaded()" name="myframe" />
Run Code Online (Sandbox Code Playgroud)
请注意,如果您的iframe源不是来自您的服务器,则无法使用包含iframe的页面中的javascript访问其内容.如果您可以访问来自其他服务器的iframe内容,则可以访问父页面中的所有数据:
window.top
Run Code Online (Sandbox Code Playgroud)
如果您无法访问iframe的页面,那么您无能为力.
归档时间: |
|
查看次数: |
30931 次 |
最近记录: |