将 iframe 更改为包含 iframe 的脚本

change iframe to script includes the iframe

本文关键字:iframe 脚本 包含      更新时间:2023-09-26

我有这部分代码:

<div class="embed">&lt;iframe id="iframe" src="<?php echo DOMAIN_NAME; ?>demo?q=<?php echo $number;?>"&gt;<body></body>&lt;/iframe&gt;</div>

我想制作一个包含这个iframe的异步脚本。所以最后我会给我的客户端异步脚本代码而不是 iframe。我想这样做有一个主要原因。如果我的网站关闭了,我不想降低我的客户发布我的 iframe 的网站/门户的速度。

当有人点击嵌入div 时,会给我的客户一个 iframe。 我想给出一个异步脚本而不是这个 iframe。可能吗?有什么想法吗?

你的意思是像

var cosnikFrame = document.createElement("iframe");
cosnikFrame.width=450;
cosnikFrame.height=300;
cosnikFrame.setAttribute("scrolling","no");
cosnikFrame.style.border=0;
document.body.appendChild(cosnikFrame);
cosnikFrame.src="http://example.com/demo.php?q=12aA1b35A4a";

或者使用例如 jQuery 在加载后推迟到:

$(function() {
  $("body").append('<iframe width='450' height='300' scrolling="no" style="border:0" src="http://example.com/demo.php?q=12aA1b35A4a"></iframe>');
});