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

Javascript outside of <HTML> tags

P: n/a
Hello.

I am attempting to write a "scraper" to download information from a
commercial web site. Oddly enough, they don't want to make this easy for me!
Their pages include plenty of Javascript, and more than a few redirects.

One that is stumping me is a small page that includes a document object
redirect in the <body> tag's onload() event. Like this:

<body
onload='javascript:document.location.replace(http://www.new_domain_goes_here.org);

The redirect does not work.

There are two <script> blocks located after the closing </HTML> tag. The
first block sets some variables. The second block inserts a .JS file
containing some _very_ convoluted Javascript code which uses some of the
variables from the first script block.

My question is:

Since this scripting is located outside of the HTML document, would the
browser run these scripts before the document onload() event is executed? If
this is the case, then perhaps this code is overriding the onload() event or
rewriting it in some way.

Thanks
-Mark

Jun 29 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Mark G. wrote:
I am attempting to write a "scraper" to download information from a
commercial web site. Oddly enough, they don't want to make this
easy for me!
That is not odd. Why let you take something when they could be charging
you for it?
Their pages include plenty of Javascript, and more than a few
redirects.

One that is stumping me is a small page that includes a document
object redirect in the <body> tag's onload() event. Like this:

<body
onload='javascript:document.location.replace(http://www.new_domain_goes_here.org);

The redirect does not work.
No it would not work as there are not quotes around the URL. So it is a
syntax error and will never be executted.

<snip> Since this scripting is located outside of the HTML document,
would the browser run these scripts before the document onload()
event is executed?
Browsers would be in their rights to ignore such scripts, but in
reality they mostly error-correct them into contents of the BODY
element.
If this is the case, then perhaps this code is overriding the onload()
event or rewriting it in some way.


No, the syntax error in the onload code is more likely the problem.

Richard.

Jun 29 '06 #2

P: n/a

"Richard Cornford" <Ri*****@litotes.demon.co.uk> wrote:

That is not odd. Why let you take something when they could be charging
you for it?
I was being facetious, of course. I do subscribe to the site.
I just want to automate what would otherwise require a
great deal of mousing around.
No it would not work as there are not quotes around the URL.
The actual URL has quotes around it. This was just my error
in typing my original post.

No, the syntax error in the onload code is more likely the problem.


Ok, thanks. I will investigate further.

-Mark
Jun 29 '06 #3

P: n/a
"Mark G." <no****@thanksanyway.org> wrote in news:1151600874.103509
@bubbleator.drizzle.com:
My question is:

Since this scripting is located outside of the HTML document, would the
browser run these scripts before the document onload() event is

executed?

You could have answered your own question by writing a simple test page:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>JS outside html</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-
8859-1">
</head>

<body onload="alert('loaded');">

Text in body.
</body>
</html>

<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
alert('after html ended');

//-->
</SCRIPT>
Jun 29 '06 #4

P: n/a
"Jim Land" <RrrrFfffTttt(NO)@(SPAM)hotmail.com> wrote:

You could have answered your own question by writing a simple test page:


But then I wouldn't have had an opportunity to thank you!

-Mark
Jun 29 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.