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?

tckmn
  • 57,719
  • 27
  • 114
  • 156
Joe.wang
  • 11,537
  • 25
  • 103
  • 180
  • 1
    4. Don't set a `src` attribute at all – Phil Dec 12 '13 at 04:45
  • What for would you need to set an iframe `src` to an invalid URI? – Bergi Dec 12 '13 at 04:47
  • But sometimes the javascript library we have to use like `ext js` include this kind of script to set `src` attribute. thanks. – Joe.wang Dec 12 '13 at 04: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 Dec 12 '13 at 04:48
  • As others have implied: this smells like [an XY problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). – Matt Ball Dec 12 '13 at 04:53
  • 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 Dec 12 '13 at 04:56
  • Just curious: what about `javascript:""`? This still uses the JavaScript Protocol - which I believe is "valid" in context - but specifies a program body (unlike `javascript:`) and should yield an empty string as opposed to "false" (from `javascript:false`). – user2864740 Dec 12 '13 at 05:11
  • :P `javascript:""` is difference from `javascript:` (I mentioned in my question.) ??? – Joe.wang Dec 12 '13 at 05:14
  • @Joe.wang Yes. `javascript:""` has a single expression (an empty string) in the body, while `javascript:` has an empty body. The different versions of IE may be treating this differently (e.g. in the case of IE10+, not accepting the latter). I suspect that this is an incompatibility introduced in IE10 for a JavaScript Protocol with an empty body. – user2864740 Dec 12 '13 at 05:15
  • 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. – Dagg Nabbit Dec 12 '13 at 05:18
  • @DaggNabbit @user2864740 :P Thanks your clarify. One of solution for this issue is just extending the library, It doesn't need change the original code(`javascript:false`) of it . and 2.x is really old version for the `extjs`. The latest version of it is up to 4.x. Another solution I think maybe trying to upgrade to 4.x in my website. Because exj team announce 4.x support IE10 . Thanks. – Joe.wang Dec 12 '13 at 05:58
  • Any reasons for changing mind to down vote? If somebody would like to tell me . It will be appreciated. Thanks. – Joe.wang Dec 13 '13 at 10:02
  • Avoid using `javascript:false` as this will break websites that do not allow inline javascript in their `Content-Security-Policy` header. Therefore it's a bad idea to use this in scripts that you expect other parties to include. – Leigh McCulloch Oct 30 '14 at 17:53

2 Answers2

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

Community
  • 1
  • 1
Dagg Nabbit
  • 75,346
  • 19
  • 113
  • 141
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.

Jon Adams
  • 24,464
  • 18
  • 82
  • 120
jfriend00
  • 683,504
  • 96
  • 985
  • 979