By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,848 Members | 3,223 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,848 IT Pros & Developers. It's quick & easy.

[beginer]Why this script failed to work?

P: n/a
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?
Sep 28 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Sep 28, 5:14*pm, devdoer <devdo...@gmail.comwrote:
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?
testtttttttttttttttttttttttttttttttttttttttttttttt tttttttttttttttttttttttttttttttttttttttttttttttttt tttttttttttttttttttttttttttttttttttttttttttttttttt tttttttttttttttttttttttttttttttttttttttttttttttttt tttttttttttttttttttttttttttttttttttttttttttttttttt tttttttttttttttttttttttttttttttttttttttttttttttttt ttttttttt
Sep 28 '08 #2

P: n/a
devdoer wrote:
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");
Why the # character in there? Maybe it's a prototype.js syntax thing, I
don't know.
alert("1");
var innerDoc = (frame1.get(0).contentDocument) ?
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.
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?
Sep 28 '08 #3

P: n/a
On Sep 28, 6:07*pm, Stevo <n...@mail.invalidwrote:
devdoer wrote:
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");

Why the # character in there? Maybe it's a prototype.js syntax thing, I
don't know.
* * * * * * * * alert("1");
* * * * * * * * var innerDoc = (frame1.get(0).contentDocument) ?

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.
Sep 28 '08 #4

P: n/a
On Sep 28, 7:14*pm, devdoer <devdo...@gmail.comwrote:
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");
That looks like something from jQuery, so ask in a jQuery forum.
--
Rob
Sep 28 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.