I have the following code in jsBin: http://jsbin.com/iRoROvu/1/edit
It basically has an anchor inside an iframe. If you click the link you will see nothing happens in Chrome but in Firefox it just goes blank.
Here's the same code in jsFiddle: http://jsfiddle.net/LbNwd/
JavaScript:
var previewFrame = document.getElementById('preview');
var preview = previewFrame.contentDocument || previewFrame.contentWindow.document;
preview.open();
preview.write("Hello World!<br/><a href='#'>Click me!</a>");
preview.close();
HTML:
<iframe id="preview"></iframe>
In this case, if you use Firefox, it creates another iframe inside the existing iframe...and keeps on doing it...like 'Inception'. But the same code works fine in Chrome.
Can anyone tell me why?
What is an iframe, and when do you use it? Developers mainly use the iframe tag to embed another HTML document within the current one. You may have crossed paths with it when you had to include a third-party widget (like the famous Facebook like button), a YouTube video, or an advertising section on your website.
Can I hide content inside an iframe from an external domain? Yes totally doable. Once you assign the parameter to a var, you could then do anything you want… like a hide() on an element.
In short, to check if a page is in an iframe, you need to compare the object's location with the window object's parent location. If they are equal, then the page is not in an iframe; otherwise, a page is in an iframe.
Yes. You should use href='javascript:void(0);'
instead href='#'
OR
You can use <a href='#' target="preview">Click me!</a>
instead.
I think adding target="preview"
also should solve your problem.
Just try it once & let us know wether its working or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With