I have a iframe, where I try hide one div element (frame with facebook).
<script type="text/javascript">
function changeCSS(){
frame = document.getElementById("radar");
frame.contentWindow.document.getElementById("div_facebook").style.display='none';
}
</script>
<iframe name="radar"
onload="javascript:changeCSS()"
id="radar"
width="650"
height="450"
frameborder="0"
scrolling="no"
src="http://radar.bourky.cz/index.php?lat=49.9847&lon=16.6241&zoom=8&map=0&repeat=3&last=4&r_opa=30&l_opa=10&l_type=0&cell=0&anim=1&c1=0&c2=0&c3=0&c4=0&c5=0">
</iframe>
And here is problem from console in chrome:
index.html:85 Uncaught DOMException: Blocked a frame with origin "null" from accessing a cross-origin frame.
at changeCSS (file:///D:/jirka/Desktop/kalend%C3%A1%C5%99/index.html:85:21)
at HTMLIFrameElement.onload (file:///D:/jirka/Desktop/kalend%C3%A1%C5%99/index.html:96:170)
I have read many instructions, but problem weren't solved.
If anyone could help I'd be very much appreciated.
The problem is you can't modify the contents of an iframe unless the domain of both the main page and the iframe are the same.
I'm guessing from what you pasted that they aren't the same, since it looks like the outer is being run locally and the iframe is from a domain (radar.bourky.cz).
You won't be able to manipulate it with JavaScript from the outside. That's a security precaution to prevent malevolent actors from doing bad things with websites. You won't be able to get around it unless you control the code both inside and outside.
Related
Current activity frame is id='1'
<iframe src="" frameborder="0",id='1'>
<iframe src="" frameborder="0",id='2'>
<div id="pwd">ddd</div>
</iframe>
</iframe>
The thing I'm trying to do here is I want to select first iframe inside second iframe, I this is the code I started with, which is not working!
$($x("//div[#id='2']"), window.frames[1])
Couldn't find the right answer, it would be great if anyone directs me to the answer or just hint me what should I do to fix it.
Thank you.
Most browsers will prevent crossing the IFrame boundary in the way you described, as it's considered a security issue. The only exception, as #Teemu mentioned, is when the frames are served from exactly the same domain, port etc. - in which case the browser will relax the restrictions
I want to get the page in which my iframe is loaded.
However my iframe is sometimes loaded inside an iframe which itself is loaded inside another iframe.
like this:
<html>
<body>
<iframe src="site_a">
<html>
<body>
<iframe src="mysite"></iframe>
</body>
</html>
</iframe>
</body>
</html>
If in the head of "mysite" I try window.top.location.href I get cross-origin errors.
<script>
(function(){
var url = window.top.location.href;
console.log(url);
})();
</script>
gives
Uncaught DOMException: Blocked a frame with origin "mysite" from accessing a cross-origin frame.
How could I get the actual url in the browser bar so I can see on which pages someone loads my iframe?
How could I get the actual url in the browser bar so I can see on which pages someone loads my iframe?
You can't.
I get cross-origin errors.
And that is why.
Your JavaScript is not allowed to monitor what people do on other websites, even if those other websites put your page in a frame.
I am using google docs viewer for show my uploaded document and i want to print it, but i can't print those document using jQuery.
I want to print iframe document but it is not by my code. how to print that document??
<button id="printbtn" onclick="myFunction()">Print</button>
<iframe src="http://docs.google.com/viewer?url=<?php echo urlencode(UPLOAD_URL.$file_name); ?>&embedded=true" frameborder="0" scrolling="no" id="iframe" style="border: none;" width="800" height="470"></iframe>
<script>
function myFunction(){
window.frames["iframe"].focus();
window.frames["iframe"].print(); // NOT WORKING
}
</script>
Please help me......
I did some digging, found its not possible,
because docs.google is going to be a different domain from yours.
I tried this,
document.querySelector('iframe').contentWindow.print()
and got 'Blocked a frame with origin "http://mydomain" from accessing a cross-origin frame.'.
Lets say, even if google allowed cross domain, the print function wont work. because google docs viewer opens another window for printing.
I've reached a conclusion that google devs have smartly made this not possible.
I have a page with 2 iframe tags:
<iframe src="top.html" seamless="seamless" width=100% height=100% id="up" name="up" frameborder="0"></iframe>
<iframe src="main.html" seamless="seamless" width=100% height=800px id="main" frameborder="0"></iframe>
Inside main.html I have the following code:
parent.frames['up'].location.href = "top.html";
The idea is to refresh the "up" iframe.
Sometimes it's working, sometimes nothing happens, and sometimes I get an exception:
Uncaught SecurityError: Blocked a frame with origin "null" from accessing a frame with origin "null". Protocols, domains, and ports must match.
What am I doing wrong?
Try below code:
parent.frames["up"].location.replace("top.html")
I found the problem.
The problem happens when loading the page by double clicking it. The domain of both the iframe and it's parent must be the same. When loading the file by double clicking it, they are both with the domain "null", and because (null===null) return false, an exception is raised.
To make this code work I had to run it from a web server.
I embedded a web page in an iFrame like this:
<iframe id="frame" src="http://www.domain.com" width="100%" frameborder="0" marginheight="0" marginwidth="0"></iframe>
Edit: The problem i am having is that the web page javascript is using the top property to find objects but now it is embedded in the iframe, is there a way to over ride this?
If I understand you right, you want to send data from the iFrame to the parent? If so, the error happens because Cross Site Communication is usually blocked to avoid XSS attacks. But you can keep your iframe, and use JavaScript and the window.postMessage(); function to share data.
https://developer.mozilla.org/en/DOM/window.postMessage