在Firefox附加组件中,如何解决错误“未定义窗口”当添加一个eventlistener到整个浏览器窗口? [英] In a Firefox Add-on how to resolve the error "window is not defined" when adding an eventlistener to the overall browser window?

查看:215
本文介绍了在Firefox附加组件中,如何解决错误“未定义窗口”当添加一个eventlistener到整个浏览器窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试添加一个eventListener到我的扩展。我想要执行一个函数,每次一个标签是活跃的(被用户点击)或新加载。

我试过这个:

  window.addEventListener(DOMContentLoaded,checkHost(),false); 

它给了我错误


未捕获的引用错误:未定义窗口

这使我非常开心,网页。请帮助我。

解决方案

通过您目前的状态: http://builder.addons.mozilla.org/package/206579/latest



在线构建器是用于使用 Addon-SDK ,其中 window 不在全局范围内 - 它不是任何特定的窗口。



标签模块,并听取准备事件或激活(一个选项卡现在集中)事件,这可能是你想要的。

  let tabs = require(' SDK /标签); 
tabs.on('ready',function(tab){
console.log(tab.url +'is ready!');
});


I try to add an eventListener to my extension. I want to execute a function everytime a tab is active (got clicked by the user) or is new loaded.

I tried this:

window.addEventListener("DOMContentLoaded", checkHost(), false);

It gives me the error

Uncaught Reference Error: window is not defined

It drives me cracy, i can't find examples on the web. Please help me.

解决方案

Via your current status: http://builder.addons.mozilla.org/package/206579/latest

The online builder is an online IDE for developing with the Addon-SDK, where window isn't in global scope -- it's not any specific window.

You can include the tabs module and listen for ready events or activate (a tab is now focused) events, which may be what you want.

let tabs = require('sdk/tabs');
tabs.on('ready', function (tab) {
  console.log(tab.url + ' is ready!');
});

这篇关于在Firefox附加组件中,如何解决错误“未定义窗口”当添加一个eventlistener到整个浏览器窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆