Get CSS attributes of an element inside iframe with cross domain [duplicate] - javascript

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

Related

How to remove div in cross site div? [duplicate]

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.

Jquery cannot get contents of <iframe> element

Hi I am trying to select form tag using Jquery from the link below in chrome console:
http://www.dcoi-conference.org/#!registration/cpq5
I tried:
$("form")
This gives empty array
Here I see the form element is in iframe. Thus I also tried
$("iframe")[0].contents();
But was uanable to get any results.
Please help.
The form in that page is in an iframe that comes from a different origin than the page. So, the browser security model will not allow you to access the iframe DOM from the parent page.
Without moving the content out of that foreign domain or placing code into that foreign sourced iframe, there is no way to work around that security limitation from just the parent page.
Possible solutions:
Stop embedding an iframe from a foreign domain because there is no way to get to the content of a cross origin iframe. Put the content into your own page directly where you can access it freely.
Add code to the foreign domain that will cooperate with the parent page. Cooperating cross origin frames can communicate via window.postMessage(), but it requires cooperating code in both frames in both domains.

Get iframe parent name which is in different domain [duplicate]

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>

If I add url "http://www.yahoo.com" in iframe, it is giving error "Refused to display, set 'X-Frame-Options' to 'DENY' ". so how to solve? [duplicate]

This question already has answers here:
Overcoming "Display forbidden by X-Frame-Options"
(27 answers)
Closed 7 years ago.
I have a iframe in page , and whatever url I type to address bar, it renders that url in the iframe, but for http://www.yahoo.com , it is showing blank iframe and giving me error "Refused to display 'https://in.yahoo.com/?p=us' in a frame because it set 'X-Frame-Options' to 'DENY'"
Now i want to handle this error, May be i can redirect user to directly to www.yahoo.com...
Please Give me Some Solution.How Can i solve it?
THANKS
You can't; Yahoo has used the X-Frame-Options header to "opt out" of having their site displayed in a frame. This header cannot be overridden by your page.
Pick another site to put in your iframe.

refresh iframe from inside itself with different domains [duplicate]

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.

Categories

Resources