Copying text from IFRAME into the INPUT field on t

2019-09-02 07:39发布

问题:

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())