最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

What does the browser do when the source of iframe is javascript - Stack Overflow

programmeradmin3浏览0评论

When the source of an iframe is:

javascript:'';

as in:

<iframe id="SpControlFrame1" name="SpControlFrame1" src="javascript:'';" path_src="index.php?cmd=YYY" ></iframe>

What is going on? What does the src="javascript:'';" tell the browser to do?

what does the "path_src" do?

Thanks Chris

When the source of an iframe is:

javascript:'';

as in:

<iframe id="SpControlFrame1" name="SpControlFrame1" src="javascript:'';" path_src="index.php?cmd=YYY" ></iframe>

What is going on? What does the src="javascript:'';" tell the browser to do?

what does the "path_src" do?

Thanks Chris

Share Improve this question edited Jan 10, 2009 at 1:53 Joel Coehoorn 416k114 gold badges578 silver badges813 bronze badges asked Jan 10, 2009 at 1:37 cbrulakcbrulak 15.6k20 gold badges63 silver badges101 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 15

It tells the browser to display the result of executing the empty string literal. Therefore, it would just display an empty string.

You can test the effect of this by typing in javascript:'http://stackoverflow.'; in the address bar of a normal window/tab. You'll get a white page that says "http://stackoverflow." and you won't actually be taken to that URL.

This is the reason that bookmarklets often wrap the code inside void() or an anonymous function that doesn't return anything to stop the browser from trying to display the result of executing the bookmarklet. For example:

javascript:void(window.open("dom_spy.html"))

Or:

javascript:(function () { window.open("dom_spy.html"); })()

If you directly use code that returns something (a new window instance in this case), the browser will end up displaying that:

javascript:window.open("dom_spy.html");

In Firefox the above will display:

[object Window]

To the best of my knowledge the src attribute maps to the iframe elements location.href. So setting src to javascript:''; is a bit nonsensical and the browser will do one of two things:

  • Ignore it because it is not a URI and does not resolve to any displayable resource
  • Execute the javascript which produced nothing

Either way you acplish very little. Is this code you inherited or are you trying to do something tricky with the iframe?

发布评论

评论列表(0)

  1. 暂无评论