开发者

Is it posible to access a javascript which resides in a script file from a iframe

i want to access a javascript function which resides in a script file from another page with iframe. my sample code :

Page from which javascript need to be access开发者_JS百科ed.

 <iframe id="FRAMESET" src="default.htm" width="0%" height="0%">
        <p>
            Your browser does not support iframes.
        </p>
    </iframe>

default.htm

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <link href="Scripts/main.js" type="text/javascript" />
</head>
<body>

</body>
</html>

main.js

function helloWorld() {
    alert("hello World");
}

i want to access this function on main page. i tried document.getElementById('FRAMESET').contentWindow.helloWorld(); but gave me error "that document.getElementById('FRAMESET').contentWindow.helloWorld();" is not a function.


It's possible. You can do this in the page that contains the frame:

document.getElementById('FRAMESET').contentWindow.helloWorld();


It's impossible. All browsers (IE, FF, Chrome) now prevent js accessing to iframe content. Why don't you just load main.js into the main page?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜