I have a React.js app and it displays inside a html iframe. How would I pass the URL params queries inside so my React app can access them. I tried to research online but couldn't find a solution for React. See code below and the solutions I tried. I get error message like TypeError: iframe is null. etc..
URL
http://website.com?param1=myname¶m1=lastname
HTML iFrame
<iframe id="myIframe" src="http://localhost:3000/myReactApp" frameborder="0">
React.JS => index.js My first try
var loc = window.location.toString(),
params = loc.split('?')[1],
iframe = document.getElementById('myIframe');
iframe.src = iframe.src + '?' + params;
console.log(iframe.src);
My second try in React.JS app
(function() {
var frameBaseSRC = document.getElementById("myIframe").src;
var frameQueryString = document.location.href.split("iFrameQuery=")[1];
if (frameQueryString != undefined) {
document.getElementById("myIframe").src = frameBaseSRC + "?q=" + frameQueryString;
}
})();