How do I check if an iframe is empty?

How do I check if an iframe is empty?

If you want to check if no page loaded inside iframe, and the iframe is not cross-domain you could check for the existence of the body tag inside of the iframe. If it exists, then something loaded. If the iframe is cross-domain, you will be blocked by the same-origin policy. Otherwise this will work.

Can you use iframe without SRC?

8 Answers. Yes, it is possible to load an empty (with no src specified) and later apply content to it using script.

What is an iframe and how it works?

An IFrame (Inline Frame) is an HTML document embedded inside another HTML document on a website. The IFrame HTML element is often used to insert content from another source, such as an advertisement, into a Web page. This capacity is enabled through JavaScript or the target attribute of an HTML anchor.

How can I hide src attribute in iframe?

iframe. setAttribute(‘src’, ‘http://your-website.org/some-link-to-iframe/’); Though it removes the url from iframe, the javascripts dynamically add that. Hope it helps!

How do I load an iframe in HTML?

Chapter Summary

  1. The HTML tag specifies an inline frame.
  2. The src attribute defines the URL of the page to embed.
  3. Always include a title attribute (for screen readers)
  4. The height and width attributes specifies the size of the iframe.
  5. Use border:none; to remove the border around the iframe.

Is it valid to have an empty iframe SRC?

No, it is not valid to specify an empty iframe src. You should use . # is ment to be a reference to an anchor within the current page (or, often used as a routing scheme when working with AJAX requests).

Can a blank iframe be added in JavaScript?

You could try adding the iframe through Javascript, so you wouldn’t need to have a blank one in the HTML: Adding the iframe with Javascript allows graceful degradation – users without Javascript won’t see a blank iframe. As part of the about URI scheme standard, about:blank is probably the best option as it has very good browser support.

Can a iframe be used as the source of an Ajax request?

Using it as the source of an iframe would be senseless, since an iframe does not reference content on the current page and is not used with AJAX requests. about:blank is a cross-browser standard to display a blank document.

What happens if you set SRC to void in JavaScript?

IE10 and FF (checked in v23 in Linux) will show ‘false’ as content. IE will show ‘cannot display the webpage’ error in the iframe. Also, when setting the src from a valid url to javascript:void (0), the page will not get blank. Works in all browsers but IE 9 sends an request to the server with path “null”. Still the best bet IMO