none
Internet Explorer 11 Problem with event.clientX RRS feed

  • Question

  • ClientX does not give me the position of the moues when i close the window

    With IE 10 it works without any Problems, i ve tested it with the last two version of the IE11 (11.0.12 and 11.0.13).

    I put a little site for testing.

    <html>
    
    <head>
    
    <meta http-equiv="X-UA-Compatible" content="IE=11"/> // To change the browser mode
    
    <title>ClientX Example</title>
    <script type="text/javascript">
    
    function onLogoff() {
    
                            if (navigator.appName == 'Netscape') { // IE 11
    
                                       var windowLaenge = (document.documentElement.clientWidth ? document.documentElement.clientWidth
    
                                                                                                  : document.body.clientWidth);
    
                                                   if (window.event.clientY <= "0"
    
                                                                           && (window.event.clientX > (windowLaenge - 16) || window.event.clientX < 16)) {
    
                                                              
    
                                       }
    
                                       alert("Netscape: X: " + window.event.clientX + "  Y:" + window.event.clientY);
    
                            }
    
                            if (navigator.appName == "Microsoft Internet Explorer") { // IE 10
    
                                       var windowLaenge = (document.documentElement.clientWidth ? document.documentElement.clientWidth
    
                                                               : document.body.clientWidth);
    
                                       if (window.event.clientY <= "0"
    
                                                               && (window.event.clientX > (windowLaenge - 16) || window.event.clientX < 16)) {
    
     
    
                                        }
    
                                       alert("Microsoft Internet Explorer: X: " + window.event.clientX + "  Y:" + window.event.clientY);
    
                            }
    
    }
    
    </script>
    
    </head>
    
    <body onbeforeunload="onLogoff()">
    
    <p>Close Window to show the alert with the position of the mouse</p>
    
    </body>
    
    </html>


     


    • Moved by Karen Hu Friday, October 31, 2014 6:44 AM dev issue
    Thursday, October 30, 2014 3:25 PM

Answers

All replies

  • Hi,

    Thanks for posting here.

    According to your description and code snippet, I can reproduce your issue on my side with IE 11.0.9600.17351 version. And I find that you are not the only one to experience this issue with IE11. Please see the similar issue link and the connect link.

    http://forums.asp.net/t/1973692.aspx?event+clientY+undefined+in+internet+explorer+11

    https://connect.microsoft.com/IE/feedback/details/810635/ie-11-clientx-and-clienty-not-working

    I would recommend that you have downloaded all of the most recent updates for Internet Explorer 11 and check to see if that helps. If still can not fix this issue, you can raise this issue to connect with this reproducing sample code.

    May


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, October 31, 2014 9:13 AM
    Moderator
  • Hi,

    this was removed from IE...for security reasons (maybe 2 years ago). (it was possible to determine the mouse position of keys used with on-screen keyboards).

    use the onbeforeunload event handler to determine if any form data should be sent before a dialog or window/tab is closed.

    see http://www.bing.com/search?q=detecting+if+a+window+was+closed+IE&src=IE-SearchBox&FORM=IESR02

    webkit has dropped support for showModalDialog.... use inline div elements instead to display popup dialogs.


    Rob^_^

    Monday, November 3, 2014 12:26 AM
  • Hi Rob,

    please take a look on my Code, i am using the onbeforeunload event handler.

    The eventhandler ist not the problem, i have to get the mousepositon on the "X" of the window.

    Because the eventhandler only should fire wenn the window was closes and not after a normal navigation.

    But there ist still a bug in the IE. Because the values of the attributes Event.currentTarget.screenY and Event.currentTarget.screenX are bad too.

    If i try it in a "normal" Window (with tabs, toolbars ect.) they give me for both -8.

    In a window which was opened with window.open (without toolbar, menubar ect) both values are 0.

    Monday, November 3, 2014 10:47 AM
  • Hi,

    since IE10 navigator.appName=='Netscape' .

    window.event.clientY is of type Number, not string "0".

    When the tab or window close button is clicked (not on the web page)... the onbeforeUnload event handler target is null,

    the correct call for the inline event handler is.

    <body onbeforeunload="onLogoff(event)">

    function onLogoff(evt){

    var el=evt.target;

    console.log(el.clientLeft);

    }

    el.clientLeft<0 does not occur when the tab or window close button is pressed so you cannot use it to feature test for the userAgent frame's close buttons events.

    Add a logout button to your page.... which navigates to an asp that clears the session cookie with the user's credentials and navigates back to the site landing page.


    Rob^_^


    Tuesday, November 4, 2014 4:47 AM
  • HI ROB,

      This is content page we are not uing body tag directly, i am using the below code

    document.body.onbeforeunload = pageClose;

    In ie11 i am getting undefine error in this properties el.clientLeft

     

    Thursday, September 3, 2015 10:39 AM
  • Hi,

    Event.currentTarget.screenX  coming 0 when we refresh/close. we need to differentiate the refresh/close.

    Thursday, September 3, 2015 10:40 AM
  • Hi,

    1. check that you do not have the same call (document.body.onbeforeunload) in your masterpage..... when you use inline event handler patterns successive event attachments clear the event stack...

    Using the IE11 dev tool place a break point in your content page's event handler (on the debug tab of dev tools) . If it doesn't break, then it is being over-written by another onbeforeclose inline event handler.

    use addEventListener instead (if targeting IE9 or higher) or a shim like jquery.on instead eg.

    function myaddeventListener(el,evt){

    if(window.addEventListener){// addEventListener code}

    else if(window.attachEvent){// IE8 and lower code}

    else {// use inline event declaration for really old IE and netscape}}

    can I ask why? (use case?)....Is this to close the session for a credential verified visitor? or on your site login page?

    Examine the Visual Studio Template projects for examples of how to use server variables and redirects on a successful login to maintain the 'logged in' state of visitors. The user session normally expires after 30mins of inactivity (no requests), otherwise uses should be given buttons/links to a logout page that first closes the session and then redirects to the site landing page.

    Regards.


    Rob^_^

    Monday, September 7, 2015 5:47 AM