当iframe的源代码是javascript时,浏览器会做什么 [英] What does the browser do when the source of iframe is javascript

查看:73
本文介绍了当iframe的源代码是javascript时,浏览器会做什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当iframe的来源为:

When the source of an iframe is:

javascript:'';

如下:

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

发生了什么事?什么是src =javascript:'';告诉浏览器要做什么?

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

path_src有什么作用?

what does the "path_src" do?

谢谢
Chris

Thanks Chris

推荐答案

它告诉浏览器显示执行空字符串文字的结果。因此,它只显示一个空字符串。

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

您可以通过输入 javascript:'http:// stackoverflow来测试其效果。 com'; 在普通窗口/标签的地址栏中。您将看到一个白色页面,上面写着 http://stackoverflow.com ,您实际上不会被带到该网址。

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

这就是为什么bookmarklet经常将代码包装在 void()或不返回任何内容的匿名函数中阻止浏览器尝试显示执行书签的结果。例如:

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"))

或者:

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");

在Firefox中,上面会显示:

In Firefox the above will display:

[object Window]

这篇关于当iframe的源代码是javascript时,浏览器会做什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆