开发者

Object doesn't support this property or method in jsp page

开发者 https://www.devze.com 2023-02-03 16:20 出处:网络
In my jsp page, I have in the <head> tag, the following code: <script type="text/javascript"

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

<script type="text/javascript"
    src="<%=request.getContextPath()%>/static/js/common/common.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 secon开发者_Go百科d part of the question is this:

The error is

Webpage error details

User Agent: Mozilla/4.0 (compatible; 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/common/common.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


how come 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 common.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

精彩评论

暂无评论...
验证码 换一张
取 消