This question already has answers here:
How to refresh an IFrame using Javascript?
(13 answers)
Closed 9 years ago.
i have a webpage which is housing my iFrame which is from a different domain.
Now i have a button inside the iFrame which when pressed, needs to refresh or reload the iframe.
I've tried a few methods which are blocked due to cross domain attempts..
In your script within the iframe, try this:
document.location.href = document.location.href;
You can't access elements outside of your document model from within the iframe, including accessing the iframe itself. You can access the properties of the document within it however.
Related
This question already has answers here:
Get DOM content of cross-domain iframe [duplicate]
(5 answers)
Closed 4 years ago.
I have an iframe youtube video, where i want to remove an div element.
I can do it in in the console as long I manually folded out the div which I am looking for, but otherwise i am not able to find it using document.getElementByClassName()..
Is it possible via js to somehow remove an div which resides inside #document?
No.
JavaScript running in a page containing an iframe element can't access the DOM of a cross-origin site loaded into that iframe.
You can send messages using postMessage, but YouTube has no API for removing arbitrary elements from the DOM in response to a message.
This question already has answers here:
Get DOM content of cross-domain iframe [duplicate]
(5 answers)
Closed 6 years ago.
I'm trying to get URL of background image for .av-video-player-bg inside this iframe:
<iframe src="http://www.gamespot.com/videos/embed/6425430/"></iframe>
I've tried
$("iframe").contents().find('.av-video-player-bg').css('background-image');
But I get this error:
Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "http://www.gamespot.com" from accessing a cross-origin frame.
If the domain of the iframe is not the same as the domain of the parent page, you will not be able to manipulate its content or get info about it due to the same origin policy
If they're different domains but you have control over its content (that is, you can add code to it), you can use Postmessaging to do what you are trying to do. Simply add a listener within the iframe's content which tells it when to fire off this change.
From looking at the domain however (gamespot) I imagine this is not your page so there isn't much you can do
This question already has answers here:
Cross domain iframe issue
(5 answers)
Closed 6 years ago.
I am new to cross domain scripting. I have a application with domain abc.com. I am integrating my app. in another website with domain xyz.com using a iframe inside a modal. On clicking a link i will open a modal with a iframe to display my app.Now I need to access iframe parent element i.e., modal and apply events on that modal(while showing and hidding modal) from code inside abc.com . I am unable to access that modal. Can any one help me. Thanks in advance.
You can access the Iframe parent from javascript insider the iframe using
parent.abc();
In the Parent you can set the document domain to be the same as the iframe content. This could help preventing cross-domain problems.
<script>
document.domain = "xyz.com";
</script>
This question already has answers here:
Stopping a iframe from loading a page using javascript
(6 answers)
Closed 7 years ago.
Is there a way in javascript to simulate pressing the "stop" button the browser whenever a link or button is clicked?
I'm trying to load other websites while displaying a frame at the top of the page, the issue is that sometimes it takes a while to load all the content on a page (especially if there is something being streamed). Is there anyway to make it so I can place a "stop" button or link on my top frame that ceases the loading of anything else?
I checked around but couldn't find anything
Thank you!
You can use the window.stop() method, however note that depending on the location of your script, JavaScript is not executed until after the DOM (typical practice), so often times the page will already be loaded before this executes.
For an iframe, simply target the frame and use the stop method.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Iframe Function Calling From Iframe to parent page javascript function
I have a JavaScript function written in my main page. It's a function that slides up the div "toggle" (with jquery).
This main page contains an iframe that is embedded into the div#toggle.
When I click on a link that belongs to the iframe I would like to execute the slide up function.
I put an onclick event on a link in the iframe (to trigger the function declared in my main page) but it doesn't work. Well, I'm not that surprised but I don't know how to make it work.
Does anyone has an idea ?
You can use window.parent to access the containing page:
window.parent.someToggleFunc();
Note that Javascript access between iframes like this are subject to the Same Origin Policy.