简体   繁体   中英

Is it possible to change iframe src using javascript exists in page inside that iframe?

I want to change the iframe source when something change in this iframe content, the iframe is in a different domian than the parent page. is this can be done or not?

I just need to add a hash to this iframe src, so that i can access this hash value from the parent page and do some stuff based on this value.

What i did:
In the iframe page i wrote: window.location.hash = "close_child";
and in the parent page i wrote: if (document.getElementById("MyIFrameId").src.indexOf("#close_child") > 0) { but i always find that the src is empty

I'm not 100% sure, but I think you should be able to do this without a problem. Since an iframe is just a frame, you should be able to change the location property from within the code inside the iframe (same as you would for anything else), and that change should be visible to the parent page whenever it is made.

Yes, it can be done. A parent object can NOT see into the iFrame, but the IFrame CAN call a JavaScript procedure from code executing within the iFrame, passing it parameters such as your hash value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM