2

If I want to set the src of iframe with these 3 value. I found:

  1. javascript: doesn't work in IE10 (error is can't find the page). other mainstream browsers or IE9 is ok.
  2. javascript:false will show a false string in the iframe for IE10, others browsers or IE9 is ok.
  3. # works fine in all the browsers.

What is the difference between them? Which one is the best choice for cross-browser issues?

13
  • 1
    4. Don't set a src attribute at all
    – Phil
    Commented Dec 12, 2013 at 4:45
  • What for would you need to set an iframe src to an invalid URI?
    – Bergi
    Commented Dec 12, 2013 at 4:47
  • 2
    @Joe.wang - please tell us the real problem you're trying to solve? What function in what library and why are you creating an iframe with no src.
    – jfriend00
    Commented Dec 12, 2013 at 4:48
  • 3
    I was using the ext js 2.x in my website, but found the Ext.SSL_SECURE_URL is initialized with javascript:false by ext js. this code caused a problem in the IE10. which is some window of ext shows a string false (I found it is because of the code iframe.src=javascript:false). so I changed Ext.SSL_SECURE_URL value to javascript:. the false string would gone . but found another problem . it would show a error page "IE can't show this page". thanks.
    – Joe.wang
    Commented Dec 12, 2013 at 4:56
  • 1
    That should actually work, although if you really just want a blank document, the standard about:blank is the way to go. Using a javascript: URI scheme to get a blank iframe is extremely weird, and someone should probably file an issue with any library that does that. Commented Dec 12, 2013 at 5:18

2 Answers 2

4

Try using about:blank as the URL. This should display a blank page in all browsers.

https://www.rfc-editor.org/rfc/rfc6694#section-3

3

If you want an iframe that doesn't load anything right away, then just don't set the src attribute to anything. You can set the .src property later via Javascript to cause it to load something.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.