为什么document.addEventListener('load',function)不能在greasemonkey脚本中工作? [英] Why doesn't document.addEventListener('load', function) work in a greasemonkey script?

查看:306
本文介绍了为什么document.addEventListener('load',function)不能在greasemonkey脚本中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它没有出错,我放了 console.log('loaded userscript wifi-autologin')控制台。 log 有效,但document.addEventListener的预期效果不会发生。在做了一些调试之后,让它打印出调用了addEventListener,我发现它没有被调用。

It doesn't give an error, and I put a console.log('loaded userscript wifi-autologin'), the console.log works, but the intended effect of the document.addEventListener doesn't happen. After doing a bit more debugging, making it print that the addEventListener was called, I discovered that it wasn't being called.

脚本来源:

// ==UserScript==
// @name        wifi-autologin
// @namespace   lf-ns
// @description Hopefully autologins to a captive portal
// @include     *://1.1.1.1/*
// @version     1
// @run-at document-end
// ==/UserScript==

document.addEventListener('load', submitAction);


推荐答案

显然, document.addEventListener ()是不可靠的,因此,我的错误。改为使用 window.addEventListener()使用相同的参数。

Apparently, document.addEventListener() is unreliable, and hence, my error. Use window.addEventListener() with the same parameters, instead.

这篇关于为什么document.addEventListener('load',function)不能在greasemonkey脚本中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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