Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Regular Coder
    Join Date
    Nov 2009
    Posts
    199
    Thanks
    23
    Thanked 0 Times in 0 Posts

    Minimum events to call on a dynamic link

    Sample:

    Code:
    <!DOCTYPE html>
    <html>
    
    <head>
        <meta charset="UTF-8">
        <title>Dynamic Link</title>
    </head>
    
    <body>
        <input type="text" value="http://www.example.com/" id="input">
        <a href="http://www.example.com/" id="link">Linked text</a>
        <script>
            var link = document.getElementById('link'),
                input = document.getElementById('input');
            link.onclick = link.oncontextmenu = link.onmousedown = function () {
                this.href = input.value;
            };
        </script>
    </body>
    
    </html>
    DEMO

    • onclick: called on the left click and keyboard focus + Enter
    • oncontextmenu: called on the right click and keyboard context menu
    • onmousedown: called on the middle click in Firefox/IE and on the link drag to the address bar

    Questions:

    1. Are there any other ways to navigate to the URL of the link -- something I forgot to cover for perfect accessibility?
    2. Can I reduce the number of events or do I have to use them all?
    Last edited by Rain Lover; 06-04-2014 at 05:52 PM.


 

Posting Permissions

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