开发者

Passing Variable or Something to Iframe Parent PHP/JS/Html

开发者 https://www.devze.com 2022-12-28 14:12 出处:网络
Alright, well this is the deal. I have a page, and then it loads an iframe. When anything inside the iframe is clicked, the main page (iframe parent) just reloads.

Alright, well this is the deal.

I have a page, and then it loads an iframe.

When anything inside the iframe is clicked, the main page (iframe parent) just reloads.

How can I have it, so that if the iframe parent is reloaded from a click inside the iframe that a certain boolean or something is p开发者_开发问答assed, displaying something different.

For the iframe, I was using

opener.location.reload();

Thanks


Rather than simply reloading, you could set the location.href back to itself, but add a querystring with the value you want to pass. Exactly how you want to do this will depend on whether the parent will already have a querystring, and whether you need to preserve that querystring. One option would be something like

var loc = opener.location;
loc.href = loc.protocol + "//" + loc.host + loc.pathname + "?myNewField=myNewValue";

(this will trim off any existing querystring or hash and add your new value as a querystring)

0

精彩评论

暂无评论...
验证码 换一张
取 消