简体   繁体   English

如何从扩展js访问和运行现场事件?

[英]How to access and run field events from extension js?

I have an extension that helps in submitting forms automatically for a process at work. 我有一个扩展程序,可以帮助您自动提交工作流程中的表单。 We are running into a problem with dual select boxes where one option is selected and then that selection changes another field's options. 我们遇到了双重选择框的问题,其中选择了一个选项,然后该选择更改了另一个字段的选项。 Since setting an option selected property to true doesn't trigger the field's onchange event I am trying to do so through code. 由于将选项的selected属性设置为true不会触发该字段的onchange事件,因此我尝试通过代码来实现。

The problem I've run into is that if I try to access or run functions on the field object from the extension, I get the error 我遇到的问题是,如果尝试从扩展名访问或运行字段对象上的函数,则会收到错误消息

Error: uncaught exception: [Exception... "Component is not available" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: chrome://webformsidebar/content/webformsidebar.js :: WebFormSidebar_FillProcess :: line 499" data: no] 错误:未捕获的异常:[Exception ...“组件不可用” nsresult:“ 0x80040111(NS_ERROR_NOT_AVAILABLE)”位置:“ JS框架:: chrome://webformsidebar/content/webformsidebar.js :: WebFormSidebar_FillProcess ::行499”数据:否]

the line causing the error is... 导致错误的行是...

if (typeof thisField.onchange === 'function')

The line right before it works just fine... 行之前的线就很好...

thisField.options[t].selected=true;

...so I'm not sure why this is resulting in such an error. ...所以我不确定为什么会导致这种错误。

What surprises me most I guess is that checking for the existence of the function leads to an error. 我最让我惊讶的是,检查函数的存在会导致错误。

It feels like the problem is related to the code running in the context of the extension instead of the browser window document. 感觉问题出在扩展程序上下文而不是浏览器窗口文档中运行的代码有关。 If so, is there any way to call a function in the browser window context instead? 如果是这样,有什么方法可以代替在浏览器窗口上下文中调用函数? Do I need to actually inject code into the page somehow? 我是否需要以某种方式实际将代码注入页面? Any other ideas? 还有其他想法吗?

我们发现可以完成此操作的唯一方法是将代码注入页面。

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

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