javascript 如何隐藏 iframe src

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9245133/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 06:02:28  来源:igfitidea点击:

How to hide iframe src

javascriptjqueryasp.net

提问by udidu

I noticed that all the Facebook applications that running inside an iframe hiding their iframe SRC, instead of the real src there is a "javascript:""". How can i do that? I want that my iframe will hide the original src

我注意到在 iframe 中运行的所有 Facebook 应用程序都隐藏了它们的 iframe SRC,而不是真正的 src 有一个“javascript:”“”。我怎样才能做到这一点?我希望我的 iframe 将隐藏原始 src

thanks!

谢谢!

回答by Tony Bogdanov

Facebook applications are loaded dynamically, which means the SRC is changed after the HTML is loaded. That is why you can only see javascript:;. The src is not hidden though, it is still there and can be obtained using javascript.

Facebook 应用程序是动态加载的,这意味着在加载 HTML 后 SRC 会发生变化。这就是为什么你只能看到javascript:;。尽管 src 并未隐藏,但它仍然存在并且可以使用 javascript 获取。

If you are using jQuery, you could use something like this:

如果您使用的是 jQuery,则可以使用以下内容:

<iframe src="javascript:;" id="myframe"></iframe>
<script>
$(document).ready(function() {
    $('#myframe').attr('src', 'http://facebook.com');
});
</script>

With this, the iframe will have javascript:;as src in the HTML, but will load facebook.com

有了这个,iframe 将javascript:;在 HTML 中作为 src,但会加载facebook.com

回答by Erik Funkenbusch

You are misunderstanding what you are seeing. Facebook is not "hiding" thi iframe src, it's just that the src is loaded via javascript. It's quite easy to see the iframe by using IE Developer tools (F12) or Firebug, or the native google chrome inspectors. There's nothing "hidden" about it, it just doesn't show up when you view source.

你误解了你所看到的。Facebook 并没有“隐藏”这个 iframe src,只是 src 是通过 javascript 加载的。使用 IE 开发工具 (F12) 或 Firebug 或本机 google chrome 检查器可以很容易地查看 iframe。没有什么“隐藏”的东西,它只是在您查看源代码时不显示。

回答by Mohan Raj

For me also want to hide src link in iframe. You can even refer to this url itself.

对我来说也想隐藏 iframe 中的 src 链接。你甚至可以参考这个网址本身。

While inspect or View page source i can't able to find the src all i can find is only its id, Title & Name, is there anyway to achieve this.

在检查或查看页面源时,我无法找到 src,我只能找到它的 id、标题和名称,无论如何都可以实现这一点。