Search code examples
javascriptjqueryiframeinputfill

Send input data outside the iframe with Jquery


Located outside the iframe, input into, what value is sent.

iframe outside

<input id="a_input_id" type="text">

iframe within

<a href="javascript:;" class="special_field_link">@r.SpecialField<a>

Javascript Code;(iframe in working)

<script>
$(function(){
$(".special_field_link").click(function(){
 $("#a_input_id").val($(this).text());
});
});
</script>

https://i.sstatic.net/nnjWH.jpg


Solution

  • As long as the iframe and the parent are in the same domain, you need to use the parent document context

    $("#a_input_id", parent.document).val($(this).text());