I would like to create an on the page, but then add the
src
later. If I make an iframe without an src
attribute, then it lo
I run into this line of code:
iframe.setAttribute("src", "javascript:false");
as well. I wanted to remove javascript:URL
.
Found this note from the Web Hypertext Application Technology Working Group [Updated 2 October 2019]
[https://html.spec.whatwg.org/multipage/iframe-embed-object.html#the-iframe-element][4.8.5_The_iframe_element]
The otherwise steps for iframe or frame elements are as follows:
If the element has no src attribute specified, or its value is the empty string, let url be the URL "about:blank".
Standard approach when creating an "empty" iframe (as an iframe shim, for example), is to set the src as javascript:false;
. This is the method used by most of the JavaScript libraries that create iframe shims for you (e.g. YUI's Overlay).
As I posted in this question: Is an empty iframe src valid?, it looks acceptable to just leave out the src=
attribute completely.
javascript:false
works in modern browsers.
What I've seen is that this only "fails" when dumb spiders try to load javascript:false
as a page.
Solution: Block the dumb spiders.
IMO: if you don't put the src, your page won't validate. But's about it. If you put a src="", your server will log many 404 errors.
Nothing is really wrong as in "damaging". But then, is it actually not wrong to use an iframe in itself?
°-
Not sure if all browsers support "about:blank", so I'd just go with your own blank page then.
Another idea: Why not add the whole iframe using javascript instead of just the src?