[英]Cannot read property 'addEventListener' of null (JavaScript Sails App)
I am trying the below JavaScript code of onsip in sails app to apply video call, but it gives the error:我正在尝试使用sails应用程序中的onsip的以下JavaScript代码来应用视频通话,但它给出了错误:
Cannot read property addEventListener' of null
无法读取 null 的属性 addEventListener'
Below is the JavaScript code for it:下面是它的 JavaScript 代码:
button.addEventListener('click', function() {
// Was on a call, so the button press means we are hanging up
if (onCall) {
onCall = false;
button.firstChild.nodeValue = 'video';
remoteRender.style.visibility = 'hidden';
session.bye();
session = null;
}
// Was not on a call, so the button press means we are ringing someone
else {
onCall = true;
button.firstChild.nodeValue = 'hang up';
remoteRender.style.visibility = 'visible';
session = makeCall(userAgent, target,
false, true,
remoteRender, null);
session.on('bye', function() {
onCall = false;
button.firstChild.nodeValue = 'video';
remoteRender.style.visibility = 'hidden';
session = null;
});
}
});
HTML code for the above is:上面的 HTML 代码是:
<button id="alice-video-button" class="right" type="button">video</button>
As i know about this error : " Cannot read property 'addEventListener' of null"据我所知,此错误:“无法读取 null 的属性‘addEventListener’”
if you get this error any where in your code, you need to check about id's and selectors.如果您在代码中的任何地方遇到此错误,则需要检查 id 和选择器。
button.addEventListener('click', function () {..}
Probably you get your error on this line and check this "button" variable is set.可能您在这一行遇到错误并检查此“按钮”变量是否已设置。
Hope this will help希望这会有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.