SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: Count browsers

  1. #1
    SitePoint Member
    Join Date
    Dec 2007
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Count browsers

    Hello, my question might be easy for some skilled java coders.
    I am trying to create a web based chat. For that I want each chater to use 1 instance of it. Ctrl + N opens the url in new window which I want to prevent.
    I thought of counting the browsers with the same window name, so if there are browsers with the same name(means someone did ctrl + N), I would call a function to close it.
    This is my way. Is it possible?
    Or you may have something in mind different for preventing the 2 instances?
    Thank you for your time!

  2. #2
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The only control you have is on the server side, by authenticating users and limiting each user to one session. Even this does not prevent someone from establishing more than one account and opening multiple windows, but it makes it more difficult.

  3. #3
    SitePoint Member
    Join Date
    Dec 2007
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello, thank you for posting.
    My problem is not when one person uses two chat windows but with different usernames. My problem is when ONE username uses the same chat room in 2(or more) windows.

  4. #4
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You still can only restrict access to a server on the server. The client has no way of knowing what's happening in other windows.

  5. #5
    SitePoint Member
    Join Date
    Dec 2007
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Damn, I was hoping it would be possible, because giving a name to a popup window it would make it trackable with javascript!
    Thanks again anyway

  6. #6
    SitePoint Member
    Join Date
    Dec 2007
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I found the solution in another forum.
    Here is how to cancel the ctrl+n function in your website

    Code JavaScript:
    function disableCtrlKeyCombination(e)
    {
            //list all CTRL + key combinations you want to disable
            var forbiddenKeys = new Array('n','c');
            var key;
            var isCtrl;
     
            if(window.event)
            {
                   key = window.event.keyCode;
                    if(window.event.ctrlKey)
                            isCtrl = true;
                    else
                            isCtrl = false;
            }
            else
            {
                    key = e.which;
                    if(e.ctrlKey)
                            isCtrl = true;
                    else
                            isCtrl = false;
            }
     
            if(isCtrl)
            {
                    for(i=0; i<forbiddenKeys .length; i++)
                    {
                            if(forbiddenKeys[i].toLowerCase() == String.fromCharCode(key).toLowerCase())
                            {
                                    return false;
                            }
                    }
            }
            return true;
    }

    And in the body tag

    Code HTML4Strict:
    onKeyPress="return disableCtrlKeyCombination(event);" onKeyDown="return disableCtrlKeyCombination(event);"

    Works perfect in IE, Firefox and Opera.

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,604
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Of course that only blocks one key combination and not the functionality itself which can still be performed using any other method.
    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="^$">

  8. #8
    SitePoint Member
    Join Date
    Dec 2007
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, I am trying to get your point, sorry I am not very good with english.

    You mean that if anyone want to use my chat with two browsers under the same username, he or she could bypass that little trick?


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
  •