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>
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:
Javascript back button for iframe parent window
(2 answers)
Closed 9 years ago.
I want to embed some third party content which will be an html page, inside my html website. I thought of using the iframe approach in which i will embed the third party html page inside my website as an iframe.
The motivation behind using iframes was that i dont know what libraries they might use, or what CSS they might write. I wanted their logic to be separate from mine. Iframe fulfills my this wish.
But now i have a problem, if i want the browser Back/Next Functionality for any navigation's inside the iframe, it will be very difficult to maintain because of the route. At the same time, maintaining the iframe state when the parent page is refreshed will be pretty tough.
So, is the iframe approach fine first of all? If it is, then how do i cater to the Browser Back/Next?
Well, you can manage back/forward button with JavaScript like this:
iframe.contentWindow.history.back();
iframe.contentWindow.history.forward();
Bigger problem is that included page can disallow possibility to be included into iframe (if you include page with this behaviour into iframe, it will load over your page - check for example this qeustion).
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.
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.