1

I am developing Mozilla Extension (Legacy extensions) by using XUL. In this

window
        .addEventListener(
                "load",
                function(event) {
                    (function(loader) {
                        loader
                                .loadSubScript("chrome://cashbackurl/content/jquery-1.11.3.min.js");
                    })
                            (Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
                                    .getService(Components.interfaces.mozIJSSubScriptLoader));

                    // Your code goes
                    myExtension.init();

                }, false);

var myExtension = {
    init : function() {
        // The event can be DOMContentLoaded, pageshow, pagehide, load or
        // unload.
        if (gBrowser)
            gBrowser.addEventListener("DOMContentLoaded", this.onPageLoad,
                    false);
    },
    onPageLoad : function(aEvent) {
        doc = aEvent.originalTarget; // doc is document that triggered
        // the event
        var win = doc.defaultView; // win is the window for the doc
        // test desired conditions and do something
        // if (doc.nodeName != "#document") return; // only documents
        // if (win != win.top) return; //only top window.
        // if (win.frameElement) return; // skip iframes/frames
        // alert("page is loaded \n" + doc.location.href);
        if (win.top == win.self) {
            cburl.getDataLoder();
        }
    }
}

Here I am using "doc" element to get referrer of current url. I tried by using doc.referrer but I am not getting correct referrer. Any once suggest me how to resolve this issue.

Thank you.

Java4you
  • 576
  • 2
  • 10
  • 20
  • To get referrer you can tab into the webNavigation object like this: http://stackoverflow.com/a/25153329/1828637 as you code your extension, make sure to make e10s friendly. as the old way is getting very out of date. consider using jpm: https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/Getting_Started_%28jpm%29 – Noitidart Nov 19 '15 at 09:15
  • 1
    Hi, I used gBrowser.webNavigation.referringURI.spec code to get referrer from current url. It is working fine when I open a url from google.com. It is not working for other sites like mysmartprice.com, cashkaro.com. It is showing null. May i know the problem why it is not showing referrer for all sites. – Java4you Nov 23 '15 at 11:34
  • I'm not sure, as you do some research please share your findings on that :) – Noitidart Nov 23 '15 at 20:38

0 Answers0