I have a GM_xmlhttpReqeust
function setup as follows (simplified version) in my Greasemonkey script.
GM_xmlhttpRequest({
synchronous: false,
method: "HEAD",
url: "http://www.example1.com",
onload: function(response){console.debug(url);},
});
GM_xmlhttpReqeust
is called in asynchronous mode in my code.Once accessed,
http://www.example1.com
does a 302 redirect tohttp://www.example2.com
I would like to access the value of the original
url
parameter (http://www.example1.com
) insideonload
callback function.As per
GM_xmlhttpReqeust
documentation,http://www.example2.com
can be found inresponse.finalUrl
insideonload
callback.
Could someone please point me to the proper Greasemonkey/JavaScript way?
The
response
passed toonload
is an object with these key properties:You want
finalUrl
, you get it like:Update for revised/clarified question:
In order to get/know the originally requested URL, you must call
GM_xmlhttpRequest()
in a closure. Like so: