Javascript - iframe 呼叫爸爸那一層的javascript function
有時候會有這樣的需求..
我有一個頁面index.html
裡面有一個javscript function 叫做 publish()
我嵌入一格iframe 叫做 b.html
希望我能夠在b.html那邊去呼叫到index.html 的 publish() function
作法如下..
index.html
<html>
<body>
<script>
var c='HELLO !! WORLD';
function publish()
{
alert(c);
}
</script>
<iframe width="500" height="300" src="b.html">
</body>
<html>
則b.html
可以透過 parent.function(); 這方法去呼叫
程式碼如下:
b.html
<html>
<body>
<script>
parent.publish();
</script>
</body>
</html>
標籤:
教學,
Javascript
|
This entry was posted on 晚上8:01
and is filed under
教學
,
Javascript
.
You can follow any responses to this entry through
the RSS 2.0 feed.
You can leave a response,
or trackback from your own site.
0 意見:
張貼留言