Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is an empty iframe src valid?

I want an iframe to initially have src as blank and then once the page loads; call a JS function and then set the src value to an actual one..

So is <iframe src="#" /> valid OR do I need to use something else like javascript:;, etc

like image 478
copenndthagen Avatar asked May 10 '11 07:05

copenndthagen


People also ask

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.

How do I create an empty iframe?

about:blank is the way to do it. Alternately, you could just insert the whole <iframe> element with JavaScript later, and don't worry about a valid "empty" src . Yea upon testing in Firefox, Chrome, Safari and IE 7/8/9 "about:blank" seems to be the best solution.

What is an iframe src?

The src attribute specifies the address of the document to embed in an iframe.

Are iframes dead?

Nope, iframes are definitely not dead.


2 Answers

just <iframe src='about:blank'></iframe>

like image 191
ariel Avatar answered Oct 24 '22 23:10

ariel


The HTML 5 working draft, section 4.8.2, says (emphasis mine):

The src attribute gives the address of a page that the nested browsing context is to contain. The attribute, if present, must be a valid non-empty URL potentially surrounded by spaces.

According to RFC 3986, valid URLs must begin with a scheme name, and relative references cannot only consist in a fragment.

Therefore, # is not a valid URL, and should not be used as the value of the src attribute.

Use about:blank instead.

like image 37
Frédéric Hamidi Avatar answered Oct 24 '22 23:10

Frédéric Hamidi