How to access query string parameters in IFRAME after redirecting back


average inquirer

I have an HTML Host1Pagewith an IFRAME whose attributes sandboxare not included, allow-top-navigationso the hosted page is not affected by any navigation that might be required within the IFRAME. Initially, the IFRAME renders the static HTML I serve, but once the user interacts with it in some way, the HTML's javascript redirects the current window (in my case the contents of the IFRAME) to another host-- Host2Page. As a result, the IFRAME renders the content Host2Page. To emphasize, I don't set the srcproperty of the IFRAME, I do window.location.href, but I can't change how the redirection works, because I don't own the code that does that redirection. After the user finishes interacting with another website, the Host2Pageuser is redirected back to the Uri corresponding to the page hosting my IFRAME- Host1Page, while the redirect Host2Pageprovides some data via query parameters. How can I access that query parameter from within the IFRAME?

I tried using myIFrame.contentWindow.location.search- but it is always empty and myIFrame.contentWindow.location.hrefalways points to the Uri of the page Host1Pagehosting the IFRAME before and after redirecting to another site .

Ed Lucas

This can be used to send parameter values ​​to the parent page if you control the content of the IFRAME that is loading after the second redirect .postMessage

const querystringParams = new URLSearchParams(window.location.search);
const querystringValue = querystringParams.get('paramINeed');

window.parent.postMessage(querystringValue, targetOrigin);

To receive messages on your parent page:

window.addEventListener("message", receiveMessage, false);

And receiveMessageas a function, it accepts an event object as a parameter.

See : https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage _

Related


How to access query string parameters in a loopback model?

lalither For model definition product.js my api endpoint looks like this api / products / 9720?id_shop = 1&id_lang = 1 I need to access id_shop in product.js to apply where clause and then get records from product table. Product.observe('access', function (ctx

How to access query string parameters in a loopback model?

lalither For model definition product.js my api endpoint looks like this api / products / 9720?id_shop = 1&id_lang = 1 I need to access id_shop in product.js to apply where clause and then get records from product table. Product.observe('access', function (ctx

How to access query string parameters in a loopback model?

lalither For model definition product.js my api endpoint looks like this api / products / 9720?id_shop = 1&id_lang = 1 I need to access id_shop in product.js to apply where clause and then get records from product table. Product.observe('access', function (ctx

How to access query string parameters in a loopback model?

lalither For model definition product.js my api endpoint looks like this api / products / 9720?id_shop = 1&id_lang = 1 I need to access id_shop in product.js to apply where clause and then get records from product table. Product.observe('access', function (ctx

How to access query string parameters in a loopback model?

lalither For model definition product.js my api endpoint looks like this api / products / 9720?id_shop = 1&id_lang = 1 I need to access id_shop in product.js to apply where clause and then get records from product table. Product.observe('access', function (ctx

How to access query string parameters in a loopback model?

lalither For model definition product.js my api endpoint looks like this api / products / 9720?id_shop = 1&id_lang = 1 I need to access id_shop in product.js to apply where clause and then get records from product table. Product.observe('access', function (ctx

How to access query string parameters in a loopback model?

lalither For model definition product.js my api endpoint looks like this api / products / 9720?id_shop = 1&id_lang = 1 I need to access id_shop in product.js to apply where clause and then get records from product table. Product.observe('access', function (ctx

How to access query string parameters in a loopback model?

lalither For model definition product.js my api endpoint looks like this api / products / 9720?id_shop = 1&id_lang = 1 I need to access id_shop in product.js to apply where clause and then get records from product table. Product.observe('access', function (ctx

How to access query string parameters in a loopback model?

lalither For model definition product.js my api endpoint looks like this api / products / 9720?id_shop = 1&id_lang = 1 I need to access id_shop in product.js to apply where clause and then get records from product table. Product.observe('access', function (ctx

How to access parameters of URL in iframe?

Javier Munoz I have the following HTML with jQuery code: <div id="info" style="width: 100%; height: 280px; overflow-y: scroll;"></div> var url1 = cbcWMS1.getGetFeatureInfoUrl (evt.coordinate, viewResolution, 'EPSG:3857', {'INFO_FORMAT': 'text/html'}); $('#in

How to access parameters of URL in iframe?

Javier Munoz I have the following HTML with jQuery code: <div id="info" style="width: 100%; height: 280px; overflow-y: scroll;"></div> var url1 = cbcWMS1.getGetFeatureInfoUrl (evt.coordinate, viewResolution, 'EPSG:3857', {'INFO_FORMAT': 'text/html'}); $('#in

Add query string parameters to YouTube URL in iframe

Tom N I have a page created through a CMS that currently looks like this: <!DOCTYPE html> <html> <head> </head> <body> <p><iframe src="//www.youtube.com/embed/id?start=1" width="560" height="315" frameborder="0" allowfullscreen="allowfullscreen" allow="a

Add query string parameters to YouTube URL in iframe

Tom N I have a page created through a CMS that currently looks like this: <!DOCTYPE html> <html> <head> </head> <body> <p><iframe src="//www.youtube.com/embed/id?start=1" width="560" height="315" frameborder="0" allowfullscreen="allowfullscreen" allow="a

How do I add headers to form the url after redirecting back?

Lamin Janneh How can I add headers to this response? public function handleDonate($data, $form) { $donate = DonationForm::create(); $donate->FullName = $data['FullName']; $donate->Amount = $data['Amount']; $donate->Email = $data['Email']; $

How do I add headers to form the url after redirecting back?

Lamin Janneh How can I add headers to this response? public function handleDonate($data, $form) { $donate = DonationForm::create(); $donate->FullName = $data['FullName']; $donate->Amount = $data['Amount']; $donate->Email = $data['Email']; $

How do I add headers to form the url after redirecting back?

Lamin Janneh How can I add headers to this response? public function handleDonate($data, $form) { $donate = DonationForm::create(); $donate->FullName = $data['FullName']; $donate->Amount = $data['Amount']; $donate->Email = $data['Email']; $

How do I add headers to form the url after redirecting back?

Lamin Janneh How can I add headers to this response? public function handleDonate($data, $form) { $donate = DonationForm::create(); $donate->FullName = $data['FullName']; $donate->Amount = $data['Amount']; $donate->Email = $data['Email']; $

How do I add headers to form the url after redirecting back?

Lamin Janneh How can I add headers to this response? public function handleDonate($data, $form) { $donate = DonationForm::create(); $donate->FullName = $data['FullName']; $donate->Amount = $data['Amount']; $donate->Email = $data['Email']; $