SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Member
    Join Date
    Aug 2003
    Location
    CA
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to cancel Alt+Home in the browser

    I would like to prevent a person from pressing Alt+Home to replace the web page with their home page. This is the code:

    <html>
    <head>
    <script>

    function CancelAltHome()
    {
    if(!window.event)
    {
    return false;
    }

    var iKeyCode = window.event.keyCode;

    if(iKeyCode == 36 && window.event.altKey)
    {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
    return false;
    }
    }

    </script>
    </head>

    <body onkeydown="CancelAltHome()">
    Test Cancelling Alt+Home
    </body>
    </html>


    If I put an alert inside the "if" I can see that the keycode is correct, but the event does not get cancelled. However, I am able to cancel Ctrl+n (creates a new window) by doing:
    if(iKeyCode == 78 && window.event.ctrlKey)

    If that works, then what is wrong with the Alt+Home case??

    Please note: I only care about IE 6

    thank you!!

  2. #2
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is just a bad idea. Who are you to tell a user they can't go to their homepage? That's just evil.
    ck :: bringing chris to the masses.

  3. #3
    Wanna-be Apple nut silver trophy M. Johansson's Avatar
    Join Date
    Sep 2000
    Location
    Halmstad, Sweden
    Posts
    7,400
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Don't do this. Focus your time on making a good site instead, and visitors will come back. This will only insure that they never do.
    Mattias Johansson
    Short, Swedish, Web Developer

    Buttons and Dog Tags with your custom design:
    FatStatement.com

  4. #4
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Besides the fact that it's a Bad Idea™, I can nigh but guarantee you that more people use the "Home" button versus the keyboard shortcut anyways.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  5. #5
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Interfering with the user's interaction with the browser is a usability (and site popularity) no-no.

    Don't do it - it's not big, and it's not clever!

    (Not to mention that application keyboard shortcuts like this *can't* be intercepted...)
    Last edited by M@rco; Oct 11, 2003 at 05:21.
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!

  6. #6
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by M@rco
    Don't do it - it's not big, and it's not clever!
    Off Topic:

    Is weirdy behind you?

  7. #7
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is a strange presence in the room, but it's not him!
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!

  8. #8
    SitePoint Member
    Join Date
    Aug 2003
    Location
    CA
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I do agree that this is not a good thing to do on a website, however, I am not creating a website for the internet. My company's software runs a webserver that is to be set up by a company for internal use, and our company's goal is to make it seem as much like an application as possible, and not like a web page. I have been assigned to cancel Alt+Home, so does anybody know how to do it or if it can be done?

  9. #9
    Vermicious Knid moncur's Avatar
    Join Date
    May 2003
    Location
    Salt Lake City, UT
    Posts
    274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It can't be done, at least in JavaScript. There might be a VBscript/activeX way to do it but you'd have to consult Microsoft's documentation.

    This is assuming you're restricting your users to Internet Explorer. If so, you should check out the IE Administration Kit - it lets you distribute a customized version of IE, and there may be a way to disable keyboard shortcuts there.

    You could also put your app in a pop-up window without a toolbar and menu - that would at least eliminate the most obvious signs that it's a browser.

  10. #10
    Wanna-be Apple nut silver trophy M. Johansson's Avatar
    Join Date
    Sep 2000
    Location
    Halmstad, Sweden
    Posts
    7,400
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by maltomeal8
    I do agree that this is not a good thing to do on a website, however, I am not creating a website for the internet. My company's software runs a webserver that is to be set up by a company for internal use, and our company's goal is to make it seem as much like an application as possible, and not like a web page.
    Why not just make it into an application, then?
    Mattias Johansson
    Short, Swedish, Web Developer

    Buttons and Dog Tags with your custom design:
    FatStatement.com

  11. #11
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    At least use an HTA
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  12. #12
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by maltomeal8
    I have been assigned to cancel Alt+Home, so does anybody know how to do it or if it can be done?
    As I said, it cannot be done. The browser application receives the keypresses, checks if they match any of its defined keyboard shortcuts, and if not, THEN passes the keypress through to the browser control. Intercepting Alt+Home is like intercepting ALT+F4. If you could do that in a web page, imagine the scope for malicious scripts!

    The *only* way to do what you want would be to build your own browser application (in VB/C++ or something, using the Internet Explorer browser control for page rendering) which doesn't implement ALT+Home (or anything else you don't want).
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!

  13. #13
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by M. Johansson
    Why not just make it into an application, then?
    Quoted in anticipation of an answer. If it's running internally and you need it to be an application, then why are you making it web-based at all? The only reason I can think of is perhaps easier deployment/changes, but with proper planning and design that wouldn't be an issue for a regular application either.


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
  •