Ryan
Ryan

Reputation: 10049

javascript (in Firefox addon) stop page load

First off: Everything works, but I would like to fine tune this a little.

Basically, in my FireFox addon I have this code in function A:

timervar = setTimeout(function() { quick.redirectToAnotherUrl(); },1500);

and in the redirecttoanotherurl function I have this:

window.content.location.href = FilterUrl;

The problem is the page loads before the redirect takes effect. Is there anyway to stop the page loading totally and then redirect as normal?

Upvotes: 1

Views: 1605

Answers (2)

Nathan Kleyn
Nathan Kleyn

Reputation: 5143

I'm not sure of the browser compatibility, but maybe try window.stop(); before your setTimeout?

For IE, you may need document.execCommand('Stop'); in addition, because as far as I know, it does not support window.stop().

Upvotes: 2

Lightness Races in Orbit
Lightness Races in Orbit

Reputation: 385395

You have a 1.5s delay specified in your argument to setTimeout.

In fact, if you want an immediate redirect, I don't understand why you're using setTimeout at all.

Just set window.content.location.href immediately.

Upvotes: 1

Related Questions