Copying text from IFRAME into the INPUT field on the parent page

只谈情不闲聊 提交于 2019-12-25 04:05:20

问题


When the visitor clicks the button after typing a text in the INPUT field which is in a framed page , is it possible to copy the typed text into the INPUT field which is on the parent page ?

iframed page code : page1.html

<form action="">
   Search:<input type="text" name="searchname"><input type="submit" value="send" size="45">
</form>

Parent page:

<IFRAME id="iframe1" src="page1.html"></IFRAME><BR>

   You searched:<INPUT type="text" id="result">

I want that the searched items display on the parent page. Thanks.


回答1:


In parent Create function which receive text...

function UpdateSearchNameToResult(msg){
   document.getElementById('result').value = msg;
}

In iframe Create function which send search name for submit button on "page1.html"

and call parent.UpdateSearchNameToResult(yourval);




回答2:


According to this answer

jquery version, you can try :

$("#result").val($("#iframe1 form input[name=searchname]").val())


来源:https://stackoverflow.com/questions/27510784/copying-text-from-iframe-into-the-input-field-on-the-parent-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!