# [jQuery] 呼叫iframe父頁面中的元素及方法 ###### tags: `jQuery` ### :triangular_flag_on_post: 在iframe中查詢父頁面元素的方法 $(‘#id', window.parent.document) example: ```=Jquery var hello = 'hello'; function getHelloWorld() { alert('hello world'); } <div id="default" style="width:200px; height:400px; float:left;">default.aspx</div> <iframe id="iframeid" src="IFrame.aspx" style="width:400px; height:400px; float:left;"></iframe> ``` ### :triangular_flag_on_post: 在iframe中呼叫父頁面中定義的方法和變數 parent.method parent.value example: ```=Jquery $(function() { //在iframe中查詢父頁面元素 alert($('#default', window.parent.document).html()); //在iframe中呼叫父頁面中定義的方法 parent.getHelloWorld(); //在iframe中呼叫父頁面中定義的變數 alert(parent.hello); }); ```