2

I have developed a Add-on for Firefox.

It has a redirect link:

https://www.google.com.vn/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0CB0QFjAA&url=https%3A%2F%2Fdeveloper.mozilla.org%2Fen-US%2FAdd-ons%2FCode_snippets%2FTabbed_browser&ei=3pfhU-TMIMPo8AXhg4GoAw&usg=AFQjCNGYBJDxF8FAEl3gxl1DcqTes93HFQ&bvm=bv.72197243,d.dGc

This link redirects to:

https://developer.mozilla.org/en-US/Add-ons/Code_snippets/Tabbed_browser

I am using this code to get redirect link before redirect

    var doc = event.originalTarget;
    var origEl = event.target || event.srcElement;
    if(origEl.tagName === 'A' || origEl.tagName === 'a') {
             alert( gBrowser.currentURI.spec);
     }

It gives:

https:// developer. mozilla. org/en-US/Add-ons/Code_snippets/Tabbed_browser

But I need the previous redirect link.

I think gBrowser.currentURI.spec get current Url of tab. I searched on Google but didn't find method to get original redirect link.

Ashish Gupta
  • 2,574
  • 2
  • 29
  • 58

1 Answers1

0
gBrowser.webNavigation.referringURI

This will give you the current tab only. If you want of a specific tab then go:

var tabIndex = 0; //first tab
var referredFromURI = gBrowser.tabContainer.childNodes[tabIndex].linkedBrowser.webNavigation.referringURI;

This isn't really the redirected from, but the referred from. But it works. If there is no referred URI than this property is null.

Also the person who downvoted your question is a loser. Good question you asked.

Noitidart
  • 35,443
  • 37
  • 154
  • 323
  • 1
    I am not 100% sure about the question but it seems the intention is to get it before it redirects. Is `referringURI` available before or after the redirect? – erosman Aug 06 '14 at 06:23
  • I try your solution but i get "xpconnect wrapped nsIUR". I need program return original link. – user3859938 Aug 22 '14 at 05:45
  • 1
    oh do a `.spec` so `referredFromURI.spec` – Noitidart Aug 22 '14 at 06:27
  • I try with input http://bit.ly/R9j52J. But it is not return http://bit.ly/R9j52J. I check some short link and some 301 redirect website . This code doesn't work ok. – user3859938 Sep 29 '14 at 02:53