如何隐藏iframe src

How to hide iframe src

本文关键字:iframe src 隐藏 何隐藏      更新时间:2023-09-26

我注意到,所有在iframe内运行的Facebook应用程序都隐藏了它们的iframe SRC,而不是真正的SRC,而是一个"javascript:""。我该怎么做?我希望我的iframe将隐藏原始src

谢谢!

Facebook应用程序是动态加载的,这意味着SRC在加载HTML后会发生更改。这就是为什么您只能看到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

Creat 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

你误解了你所看到的。Facebook并没有"隐藏"iframe src,只是通过javascript加载了src。通过使用IE Developer工具(F12)或Firebug,或者本地的googlechrome检查器,很容易看到iframe。它并没有任何"隐藏"之处,只是在查看源代码时不会显示出来。