开发者

Help debugging window.event.screenX

开发者 https://www.devze.com 2023-02-27 08:00 出处:网络
I\'m using firebug and the latest FF to debug this bit of javascript.When line #30 is hit in the debugger the screen tries to refresh with message

I'm using firebug and the latest FF to debug this bit of javascript. When line #30 is hit in the debugger the screen tries to refresh with message

"To display this page, firefox must send information that will repeat any action (such as a search or order confirmation) that was performed earlier.

Javascript with line #'s Called via OnClick()

function EnterComment(divName, /*...couple other params*/) {
25
26 thatDiv = divName;
27 //...comment
28
29 // Mouse Position with offset
30 var x = window.event.screenX +开发者_开发技巧 10;
31 var y = document.body.scrollTop + 20; 

This doesn't work in IE either. Is there any way to get an exception from Firebug? Any other tips to fix this?


Firefox doesn't have a global "event" object at all. Instead, a reference to an essentially similar object is passed in to event handlers by the runtime system.

I can't tell what sort of code is that fragment you posted. As an example, if you're binding event handlers with the basic DOM 0 attributes, you can do this:

<a onclick='yourhandler(event)'>hi</a>

and then:

function yourhandler(event) {
  event = event || window.event;
  var X = event.screenX;
  // ...
}

If, as you mention in a comment, you were to use jQuery to bind handlers, then it's even easier because it's the same in all browsers:

$(function() {
  $('#myAnchor').click(function(event) {
    var X = event.pageX;
  });
});
0

精彩评论

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