[英]TypeError: undefined is not a function in gwt when inject javascript
When I try to inject this javascript code in my GWT project through ScriptInjector.fromString()
it throws an error 当我尝试通过
ScriptInjector.fromString()
在我的GWT项目中注入此javascript代码时,会引发错误
TypeError: undefined is not a function
Here is my code: TypeError: undefined is not a function
这是我的代码:
(function(window) {
var $canvas,
onResize = function(event) {
$canvas.attr({
height: window.innerHeight,
width: window.innerWidth
});
};
$(document).ready(function() {
$canvas = $('canvas');
window.addEventListener('orientationchange', onResize, false);
window.addEventListener('resize', onResize, false);
onResize();
$('form').signaturePad({
drawOnly: true,
defaultAction: 'drawIt',
validateFields: false,
lineWidth: 0,
output: null,
sigNav: null,
name: null,
typed: null,
clear: 'input[type=reset]',
typeIt: null,
drawIt: null,
typeItDesc: null,
drawItDesc: null
});
});
}(this));
The final javascript after injecting it in gwt own file which i found in inspect element was like below: 将其注入到我在inspect元素中找到的gwt自己的文件中后,最终的javascript如下所示:
function com_google_gwt_core_client_ScriptInjector$FromString_ScriptInjector$FromString__Ljava_lang_String_2V(){
this.com_google_gwt_core_client_ScriptInjector$FromString_scriptBody = "(function(window) {var $canvas,onResize = function(event) {}; $(document).ready(function() { $canvas = $('canvas'); window.addEventListener('orientationchange', onResize, false);window.addEventListener('resize', onResize, false);onResize(); $('form').signaturePad({drawOnly: true, defaultAction: 'drawIt', validateFields: false,lineWidth: 0, output: null,sigNav: null,name: null,typed: null,clear: 'input[type=reset]',typeIt: null,drawIt: null,typeItDesc: null,drawItDesc: null})})}(this));";
}
Any help will be highly appreciated. 任何帮助将不胜感激。 Thank you
谢谢
I'd bet you're injecting your script in the wrong window and $
isn't defined there. 我敢打赌,您在错误的窗口中注入了脚本,并且
$
在那里没有定义。
Most of the time, you want to inject script in the page you load your *.nocache.js
script in, not the one (hidden iframe) GWT code actually runs, so don't forget to tell it to the ScriptInjector
: 大多数时候,您想在加载
*.nocache.js
脚本的页面中注入脚本,而不是实际运行的那个(隐藏的iframe)GWT代码,因此请不要忘记将其告诉ScriptInjector
:
ScriptInjector.fromString(theScript)
.setWindow(ScriptInjector.TOP_WINDOW)
.inject();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.