Is there an event listener for when the page starts loading?

D

Daz

Hi,

I am trying to find an event listener which will trigger when the pages
starts loading, as opposed to when it's finished, or when the DOM
content has finished loading. I am sure that such a listener exists,
but I can't seem to find it. I would appreciate any pointers.

Many thanks.

Daz.
 
M

Michael Winter

Daz said:
I am trying to find an event listener which will trigger when the
pages starts loading,

What would be the point in that? Such an event would have already fired
before a script could add a listener: the document must already be in
the process of loading for a script to executed.

[snip]

Mike
 
Y

yb

I am trying to find an event listener which will trigger when the pages
starts loading, as opposed to when it's finished, or when the DOM
content has finished loading. I am sure that such a listener exists,
but I can't seem to find it. I would appreciate any pointers.

Any scripts you include in the <head> will execute before the body
starts loading. Just be careful not to reference DOM elements which
haven't been parsed and created yet.

just curious, what do you need to do before the page loads?
 
L

Lee

Daz said:
Hi,

I am trying to find an event listener which will trigger when the pages
starts loading, as opposed to when it's finished, or when the DOM
content has finished loading. I am sure that such a listener exists,
but I can't seem to find it. I would appreciate any pointers.

When the page begins to load, it isn't aware of any of your code,
so how could it possibly invoke your method?

Just put inline code in the <head> section of the page.


--
 
D

Daz

yb said:
Any scripts you include in the <head> will execute before the body
starts loading. Just be careful not to reference DOM elements which
haven't been parsed and created yet.

just curious, what do you need to do before the page loads?

I am making a Firefox extension which will work on named sites, and
strip out the <script> tags for Google Ads, as the page loads. At the
moment, the page is taking 2-5 times longer to load because it's
waiting for ad2.googlesyndication.com. With these stripped, it should
be even quicker. Alternatively, I need to find a way of stopping the
script from even executing, but I am not sure if I can...

Thanks.

Daz.
 
D

Daz

Michael said:
Daz said:
I am trying to find an event listener which will trigger when the
pages starts loading,

What would be the point in that? Such an event would have already fired
before a script could add a listener: the document must already be in
the process of loading for a script to executed.

[snip]

Mike

Hi Mike,

You are right to an extent. The javascript is run from outside of the
page by the browser. It's loaded when the browser is fired up, and
stays there until the browser is closed. What you are saying makes
sense, however. Perhaps I am either looking for something Firefox
specific, as in regular JavaScript there is no use for such a listener,
or perhaps I could do something with the document.location object?

Thanks for your input.

Daz.
 
D

Daz

Lee said:
Daz said:

When the page begins to load, it isn't aware of any of your code,
so how could it possibly invoke your method?

Just put inline code in the <head> section of the page.


--

Ok, I have just figured it out. What I needed was a a
WebProgressListener, which is completely unrelated to JavaScript. Sorry
for the confusion, and thanks for your input everyone.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top