I have shortened URL's scanned from QRCODES. The full URL has some parameters that I need.
I'm putting up an Iframe to load the shortened URL and was hoping to get the "full" url once it loaded.
But didn't get to work...
Is it possible?
Once the Iframe is loaded, I try access it using:
iframe.contentWindow.location.href
But always get an error
ERROR DOMException: Blocked a frame with origin "http://localhost:8100" from accessing a cross-origin frame.
There are solutions to the communication between iframe and host if you control the content of both windows, but they often feel like hacks and can be limiting.
For a general solution, you could get the redirected URL before you even load the iframe.
The fetch api has a "redirect" option you can set to "manual" to get the URL it redirects to.
fetch(shorturl, {redirect: "manual"})
.then(function(response) {
var iframeurl;
if (response.type==="opaqueredirect") {
// set to redirected url
iframeurl = response.url
}
else {
// use original url.
iframeurl = shorturl
}
iframe.contentWindow.location.href = iframeurl;
handleQueryString(iframeurl)
})