最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Object doesn't support this property or method in jsp page - Stack Overflow

programmeradmin0浏览0评论

In my jsp page, I have in the <head> tag, the following code:

<script type="text/javascript"
    src="<%=request.getContextPath()%>/static/js/mon/mon.js"></script>    
<script type="text/javascript">

    // Function for Suppressing the JS Error
    function silentErrorHandler() {return true;}
    window.onerror=silentErrorHandler;

</script>

If there is some JavaScript executing on the jsp page after this, then I guess silentErrorHandler() will have no effect. i.e. the error will still show on page. Is this correct? Because the error is showing and am not sure why. The second part of the question is this:
The error is

Webpage error details

User Agent: Mozilla/4.0 (patible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; AskTbFXTV5/5.9.1.14019)
Timestamp: Fri, 7 Jan 2011 21:26:23 UTC

Message: Object doesn't support this property or method
Line: 613
Char: 1
Code: 0
URI: http://localhost:9080/Claris/static/js/mon/mon.js

And finally, line 613 states

document.captureEvents(Event.MOUSEUP);

There is error on IE8. Runs fine on Mozilla and IE7. Any suggestions will be very helpful

In my jsp page, I have in the <head> tag, the following code:

<script type="text/javascript"
    src="<%=request.getContextPath()%>/static/js/mon/mon.js"></script>    
<script type="text/javascript">

    // Function for Suppressing the JS Error
    function silentErrorHandler() {return true;}
    window.onerror=silentErrorHandler;

</script>

If there is some JavaScript executing on the jsp page after this, then I guess silentErrorHandler() will have no effect. i.e. the error will still show on page. Is this correct? Because the error is showing and am not sure why. The second part of the question is this:
The error is

Webpage error details

User Agent: Mozilla/4.0 (patible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; AskTbFXTV5/5.9.1.14019)
Timestamp: Fri, 7 Jan 2011 21:26:23 UTC

Message: Object doesn't support this property or method
Line: 613
Char: 1
Code: 0
URI: http://localhost:9080/Claris/static/js/mon/mon.js

And finally, line 613 states

document.captureEvents(Event.MOUSEUP);

There is error on IE8. Runs fine on Mozilla and IE7. Any suggestions will be very helpful

Share Improve this question edited Jan 5, 2023 at 21:42 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Jan 7, 2011 at 21:30 VictorVictor 17.1k74 gold badges241 silver badges439 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

how e it works in IE7?

captureEvents() is an unpleasant, unreliable event interface from the Netscape 4 era that was always doubtful and should not be used for anything. Newer versions of both IE and Firefox drop support for it. It sounds like your scripts need some fairly serious updating.

Adding an error sink is also a pretty bad idea. Sweeping your errors under the carpet makes your error-finding job more difficult, and doesn't affect regular users (since they will have browsers' default settings of not opening a report for JS errors).

So in newer IE8, we can do document.onmouseup = someFunction; without having to do document.captureEvents(Event.MOUSEUP); Correct?

Yes, but that's using ‘bubbling’ rather than ‘capturing’. In this case the events will still be fired on the descendent elements, and will ‘bubble’ up through each of the ancestors until it hits the document.

The idea of ‘capture’ is that the ancestor element (document) can prevent the descendent elements getting any notification of the event at all. Event capturing isn't often needed in practice and is a pain because it's done differently on different browsers.

IE uses the setCapture() method. Other modern browsers use the W3C DOM Events model, passing true as the third argument to addEventListener() (this doesn't work with the DOM 0 event model of assigning a function to onclick et al). captureEvents() was how it was done in ancient Netscape. Other older or niche browsers have no means of event capturing at all.

In general: best avoid event capturing. Check the script really requires it. Possibly not: if this is a script intended to run on Netscape 4 (retch), it may have used captureEvents() even if it didn't need capturing, because there were some broken parts of the Netscape event model that didn't work right with bubbling.

Your error points to a line inside the script file that is loaded before you set the onerror suppression.

If you put it before you include mon.js, it should work.

That said, you should really try to find the error and fix it... or wrap it in a try/catch if the exception isn't really an issue.

e.g. in your case (using IE) you will get an error because document in IE does not have a document.captureEvents property/method.

发布评论

评论列表(0)

  1. 暂无评论