Access to a variable in an iframe by jquery select

2019-06-25 14:58发布

问题:

I have following:

<iframe id="test">
   <script>
     variable='hi';
   </script>
</iframe>

I need to know how can I access to a variable by jquery selector from the top window like this $("#test").variable ?

回答1:

You can try :

$("#test")[0].contentWindow.variable;


标签: jquery iframe