[beginer]Why this script failed to work?

D

devdoer

HI:

I paste my script below:

<html>
<head>
<script src="http://code.activestate.com/js/jquery-1.2.1.js"
type="text/javascript"></script>

<script language="javascript" type="text/javascript">
function onLoad() {
var frame1 = $("#frame1");
alert("1");
var innerDoc = (frame1.get(0).contentDocument) ?
frame1.get(0).contentDocument : frame1.get(0).contentWindow.document;
alert("2");
var b=innerDoc.body;
alert("3");
alert(innerDoc.body.scrollHeight);
}
</script>

</head>
<body>
<iframe id="frame1" src="http://www.baidu.com" width=100%
onload="onLoad()">
</body>
</html>

The script only alert "1" in IE and alert "2" in firefox. It seems
stop execute after then.

Does any guy know why?
 
W

webzhao

HI:

I paste my script below:

<html>
    <head>
        <script src="http://code.activestate.com/js/jquery-1.2.1.js"
type="text/javascript"></script>

        <script language="javascript" type="text/javascript">
            function onLoad() {
                var frame1 = $("#frame1");
                alert("1");
                var innerDoc = (frame1.get(0).contentDocument) ?
frame1.get(0).contentDocument : frame1.get(0).contentWindow.document;
                alert("2");
                var b=innerDoc.body;
                alert("3");
                alert(innerDoc.body.scrollHeight);
            }
        </script>

    </head>
    <body>
        <iframe  id="frame1" src="http://www.baidu.com" width=100%
onload="onLoad()">
        </body>
    </html>

The script only alert "1" in IE and alert "2" in firefox. It seems
stop execute after then.

Does any guy know why?

testttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt
 
D

devdoer

Why the # character in there? Maybe it's a prototype.js syntax thing, I
don't know.


You're not checking first if frame1 != null, which it would be if that #
above was wrong. You're also trying to access the contentDocument of a
page in a different domain. This is actively blocked by the browsers for
security reasons.

But by using firebug, I can view the innerDoc 's content and other
attributes in the debug window.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top