SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2013
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simulate onClick without click

    Hi, this is my first post, I have a chat script wehere the user have to click a icon to leave, but some times (most of the times) they close the browser and the operator ignore it.
    The close chat button its this one : <a class="closethread" href="javascript:void(0)" onClick="return false;" title="close chat">Close Chat</a>.
    The idea is...when the user close the browser a function onBeforeUnload trig the link to make the class "closedthread" id"closedthread" bacome false without click.
    I tried it with: <body class="closedthread" id"closedthread" onBeforeUnload="return false;">, but it works ONLY in IE9.

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,871
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Most browsers now limit what onbeforeunload can be used for because a lot of sites misuse it. Also some people disable that event in their browser because of the annoying way it is misused.

    The only guaranteed way to determine if the web page is still open or not is to use a heartbeat script to track from the server whether the page is still open or not.

    http://javascriptexample.net/ajax09.php has an example where you can track how long someone is on the page. To get what you require you'd then need to add a cron job that runs every so often to look to see who has left and to close their chat.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Member
    Join Date
    Jun 2013
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for the answer, but the chat have that already and check for window open every 1 minute, what I was thinking is about something like this:
    <script language="JavaScript">
    window.onbeforeunload = confirmExit;
    function confirmExit()

    \\ Here -> body return false;
    {
    return message to display in dialog box;
    }
    </script>

    With the confirmation alert make the body or the link return false.
    As you see I don't know about javascript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •