繁体   English   中英

使用jQuery将对外部PHP脚本标签的调用插入到元素中

[英]Insert call to external PHP script tag into element using jQuery

我需要使用jQuery将以下内容插入页脚。 它会生成一个小的广告横幅。

<script src="http://14489-001.pod1.us01.hst.inclickadserver.com/ads/ads.php?t=MTAwMjsxO2hvcml6b250YWwubGVhZGVyYm9hcmQ=&index=1"></script>

我尝试以下无济于事:

    var s = document.createElement("script");
    s.src = "http://14489-001.pod1.us01.hst.inclickadserver.com/ads/ads.php?t=MTAwMjsxO2hvcml6b250YWwubGVhZGVyYm9hcmQ=&index=1";
    $(".copyright-container").prepend(s);

以及类似的东西:

$("<script src='http://14489-001.pod1.us01.hst.inclickadserver.com/ads/ads.php?t=MTAwMjsxO2hvcml6b250YWwubGVhZGVyYm9hcmQ=&index=1'></scr" + "ipt>").insertBefore('.copyright-container');

Chrome的控制台没有出现任何错误,但没有任何显示。 如果我将脚本标记粘贴到网站上任何页面的正文中,就会显示广告。

根据您加载js的方式,它可能无法评估。 jQuery具有getScript函数,尽管将其用于跨站点js文件可能很困难。 这是一些示例代码。

$.getScript( "ajax/test.js", function( data, textStatus, jqxhr ) {
  console.log( data ); // Data returned
  console.log( textStatus ); // Success
  console.log( jqxhr.status ); // 200
  console.log( "Load was performed." );
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM