Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

The right way to do URL redirection

3 views
Skip to first unread message

marko.a...@gmail.com

unread,
Jun 24, 2007, 1:28:56 PM6/24/07
to
Hello,

My extension should perform URL redirection on certain URL patterns.
This should happen for all HTTP requests.

The closest I got to is to add my progress listenert with
addProgressListener()
and then, in onStateChange(), in case of flag indicating STATE_START,
then changing window.document.location.href. However this does not
work
right, after the redirection somehow the all the bars (menu, toolbar,
location,
bookmarks) dissappear and I don't even see the redirection happenning
again.

Do you have any suggestions?

Marko

Joe Devietti

unread,
Nov 25, 2008, 1:31:41 AM11/25/08
to
Hey,

I was able to get this to work in FF 3.0.4 by using the following code
inside my onStateChange() handler:

if ( (aFlag & (STATE_IS_DOCUMENT|STATE_START)) && doTriggerRedirect ) {
aRequest.cancel( 0x804b0002 ); // NS_BINDING_ABORTED
gBrowser.loadURI( redirect_url );
doTriggerRedirect = false;
}

The only other trick is that you probably want the redirect to trigger
only once, so I used the doTriggerRedirect global flag.

The magic to cancel the pending request is due to
t...@gigasoftdevelopment.com who posted about this a few months ago.

hth,
joe

Joe Devietti

unread,
Nov 26, 2008, 5:05:38 AM11/26/08
to
Hmmm, I spoke too soon. This worked fine when loading static webpages
off my hdd, but doesn't work for real web pages.

Does anybody know what's wrong? I've tried replacing STATE_IS_DOCUMENT
with STATE_IS_NETWORK, and also removing it entirely, and neither of
these helps.

joe

Joe Devietti

unread,
Nov 26, 2008, 5:17:12 AM11/26/08
to
Okay, I finally figured this out, thanks to google and http://
www.nabble.com/Redirect-URL-from-extension-td11732227.html:

gURLBar.value = newurl; // sets the location bar value
handleURLBarCommand(); // loads the URL in the location bar

works like a charm!

0 new messages