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
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.
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.
The src attribute specifies the address of the document to embed in an iframe.
Nope, iframes are definitely not dead.
just <iframe src='about:blank'></iframe>
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.
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