简体   繁体   English

如何使用Firefox扩展注入Javascript

[英]How do I Inject Javascript with Firefox Extension

I am building a Firefox extension and have come a long way. 我正在构建Firefox扩展,并且已经走了很长一段路。 One of the parts of my extension is where I display a DIV at the bottom of the page and I want to put an ad into the div, but for some reason every time it does so, it redirects to another page entirely with the ad on it. 扩展程序的一部分是在页面底部显示DIV,我想将广告放入div,但由于某种原因,每次这样做,它都会完全重定向到另一个页面它。 So it looks like its not allowing me to insert this code below into the div that sits at the bottom. 因此,似乎不允许我将下面的代码插入位于底部的div中。 Any chance anyone can help? 任何人都可以提供帮助的机会吗?

This code of course calls the "ad_display.js" file and thats where it does the redirect. 该代码当然会调用“ ad_display.js”文件,这就是重定向的位置。 Any way I can do this or am I stuck in the water? 我能做到这一点还是被卡在水中?

Thanks!!! 谢谢!!!

    <!-- Beginning of Project Wonderful ad code: -->
<!-- Ad box ID: 38154 -->
<script type="text/javascript">
<!--
var pw_d=document;
pw_d.projectwonderful_adbox_id = "38154";
pw_d.projectwonderful_adbox_type = "2";
pw_d.projectwonderful_foreground_color = "";
pw_d.projectwonderful_background_color = "";
//-->
</script>
<script type="text/javascript" src="http://www.projectwonderful.com/ad_display.js"></script>
<!-- End of Project Wonderful ad code. -->

Two solutions: 两种解决方案:

  • Either you replicate the functionality of that ad_display script, change "document.write(pw_s)" to something a little saner like "document.getElementById('mydivwithanad').innerHTML=pw_s" 复制该ad_display脚本的功能后,将“ document.write(pw_s)”更改为更合理的名称,例如“ document.getElementById('mydivwithanad')。innerHTML = pw_s”
  • Ether you use insert an iframe in the page rather than a div, and you inject that code in the iframe. 您可以使用Ether在页面中而不是div插入iframe,然后将代码插入iframe。

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

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