views:

188

answers:

2

Hi, I'm writing a firefox addon, and if certain conditions are met, id like to rewrite the URL. Right now its being done in the following fashion

if(checkUrl(document.location.href))
{
    document.location.replace('xyz.com');
}

the problem with this is that the old page loads, then the condition is met, and only then is the user redirected.

Is there a way to do this before the page loads? i.e., once the user has typed in the url and hit enter (or clicked?)

Thanks!

A: 

If you place at the beginning of the body tag:

<script>
document.location.replace('xyz.com')
</script>

That should work.

Mic
again, this would only kick in once the original page loads.i'm trying to get it done before the browser starts loading the page, to save that extra flicker as the user gets redirected.
daniel
Ah... then you need to do it server side, using a mod rewrite or another method
Mic
Sorry for the noise, you are in a firefox plugin... no server here
Mic
A: 

for any future readers: https://developer.mozilla.org/en/Code_snippets/Progress_Listeners

daniel