HTML embedded PDF iframe

It’s downloaded probably because there is not Adobe Reader plug-in installed. In this case, IE (it doesn’t matter which version) doesn’t know how to render it, and it’ll simply download the file (Chrome, for example, has its own embedded PDF renderer). If you want to try to detect PDF support you could: !!navigator.mimeTypes[“application/pdf”]?.enabledPlugin (now deprecated, … Read more

How to add click event to a iframe with JQuery

There’s no ‘onclick’ event for an iframe, but you can try to catch the click event of the document in the iframe: document.getElementById(“iframe_id”).contentWindow.document.body.onclick = function() { alert(“iframe clicked”); } EDIT Though this doesn’t solve your cross site problem, FYI jQuery has been updated to play well with iFrames: $(‘#iframe_id’).on(‘click’, function(event) { }); Update 1/2015 The … Read more

iFrame src change event detection?

You may want to use the onLoad event, as in the following example: <iframe src=”http://www.google.com/” onLoad=”alert(‘Test’);”></iframe> The alert will pop-up whenever the location within the iframe changes. It works in all modern browsers, but may not work in some very older browsers like IE5 and early Opera. (Source) If the iframe is showing a page … Read more

Get current URL from IFRAME

For security reasons, you can only get the url for as long as the contents of the iframe, and the referencing javascript, are served from the same domain. As long as that is true, something like this will work: document.getElementById(“iframe_id”).contentWindow.location.href If the two domains are mismatched, you’ll run into cross site reference scripting security restrictions. … Read more

jQuery .ready in a dynamically inserted iframe

I answered a similar question (see Javascript callback when IFRAME is finished loading?). You can obtain control over the iframe load event with the following code: function callIframe(url, callback) { $(document.body).append(‘<IFRAME id=”myId” …>’); $(‘iframe#myId’).attr(‘src’, url); $(‘iframe#myId’).load(function() { callback(this); }); } In dealing with iframes I found good enough to use load event instead of document … Read more

Make iframe automatically adjust height according to the contents without using scrollbar? [duplicate]

Add this to your <head> section: <script> function resizeIframe(obj) { obj.style.height = obj.contentWindow.document.documentElement.scrollHeight + ‘px’; } </script> And change your iframe to this: <iframe src=”https://stackoverflow.com/questions/9975810/…” frameborder=”0″ scrolling=”no” onload=”resizeIframe(this)” /> As found on sitepoint discussion.

Access iframe elements in JavaScript

If your iframe is in the same domain as your parent page you can access the elements using window.frames collection. // replace myIFrame with your iFrame id // replace myIFrameElemId with your iFrame’s element id // you can work on window.frames[‘myIFrame’].document like you are working on // normal document object in JS window.frames[‘myIFrame’].document.getElementById(‘myIFrameElemId’) If your … Read more

How do I get the current location of an iframe?

I did some tests in Firefox 3 comparing the value of .src and .documentWindow.location.href in an iframe. (Note: The documentWindow is called contentDocument in Chrome, so instead of .documentWindow.location.href in Chrome it will be .contentDocument.location.href.) src is always the last URL that was loaded in the iframe without user interaction. I.e., it contains the first … Read more