如何隐藏iframe src

时间:2012-02-11 23:54:21

标签: javascript jquery asp.net

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

谢谢!

4 个答案:

答案 0 :(得分:13)

Facebook应用程序是动态加载的,这意味着在加载HTML后会更改SRC。这就是为什么你只能看到javascript:;的原因。 src虽然没有隐藏,它仍然存在,可以使用javascript获得。

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

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

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

答案 1 :(得分:2)

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

答案 2 :(得分:1)

创建elem HTML:

<div id="htmlTest"></div>

JS代码:

var blobMe= URL['createObjectURL'](new Blob([''], {type: 'text/html'}));
var elIframe = document['createElement']('iframe');
elIframe['setAttribute']('frameborder', '0');
elIframe['setAttribute']('width', '100%');
elIframe['setAttribute']('height', '500px');
elIframe['setAttribute']('allowfullscreen', 'true');
elIframe['setAttribute']('webkitallowfullscreen', 'true');
elIframe['setAttribute']('mozallowfullscreen', 'true');
elIframe['setAttribute']('src', blobMe);
var idOne= 'gepa_'+ Date.now();
elIframe['setAttribute']('id', idOne);
document.getElementById('htmlTest').appendChild(elIframe);
const iframeHere= 'https://www.youtube.com/embed/GdIEi4lIH_Q';
document['getElementById'](idOne)['contentWindow']['document'].write('<script type="text/javascript">location.href = "' + iframeHere + '";</script>')

来源: https://www.nodejsauto.com/2020/08/iframe-where-src-what-is-blob.html

答案 3 :(得分:0)

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

在检查或查看页面源我无法找到src时我只能找到它的ID,标题&amp;姓名,无论如何都要实现这一点。

相关问题