www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 25

Thread: Left Mouse Click Doesn't Work only Open New Tab

  1. #1
    Join Date
    Jul 2009
    Posts
    138

    Arrow Left Mouse Click Doesn't Work only Open New Tab

    Could someone tell me why I can not click the link using left mouse button but I have to click right button and then open in new tab ?? Code below.


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <script type="text/javascript">
    window.onload=function() {
    document.getElementById('menu').onclick = active;
    };

    function active(e) {
    if ( typeof active.aLinks == 'undefined' ) { // save the list
    var aObj = document.getElementById('menu').getElementsByTagName('a');
    var i = aObj.length;
    active.aLinks = [];
    while(i--) {
    active.aLinks.push(aObj[i]);
    }
    }
    var e = e? e : window.event;
    var target = e.srcElement || e.target;
    if(target.nodeName.toUpperCase()=='A') {
    var i = active.aLinks.length;
    var aLinks = [];
    while(i--) {
    active.aLinks[i].style.background = '#ccc'; // reset background
    }
    target.style.background = '#9cf'; // active link
    }
    return false;
    }
    </script>

    <style type="text/css">
    #menu {width:7em;}
    #menu a {display:block; background:#ccc; padding:2px 5px;}
    </style>

    </head>
    <body>
    <ul id="menu">
    <li><a href="home.htm">home</a></li>
    <li><a href="pruducts.htm">pruducts</a></li>
    <li><a href="contact.htm">contact</a></li>
    </ul>
    </body>
    </html>

  2. #2
    Join Date
    Dec 2008
    Posts
    488
    I"m kind of confused about what it is you're trying to do here. It looks like you're just trying to attach an onclick event to some links, however it's actually attached to the UL tag. Since you're checking to see if the event source target is a link, it's going to return false, which is what causes it not to go anywhere, and it's not going to change any links' colors because you're not actually getting the links as a source target.

    Please describe exactly what you want to happen when someone clicks a link and we can come up with a better, simpler way to go about this. If I'm looking at this right, you simply want to change the clicked link to 1 color and the other links to another, is that right?

  3. #3
    Join Date
    Jul 2009
    Posts
    138

    Arrow

    Please copy whole code in to the file and run it click then Home and tell me why the home.htm will not open ? You have to click right mouse then open in new tab, then its open.

    Everything is working the way I need , just this click doesn't, could you help me please?
    Last edited by spacemoc; 07-21-2011 at 03:32 AM.

  4. #4
    Join Date
    Jul 2009
    Posts
    138

    Arrow Links

    does anyone know how to change above code to allow me click the links?

  5. #5
    Join Date
    Jul 2009
    Posts
    138

    Arrow Solution

    Does anyone know solution for that problem? please

  6. #6
    Join Date
    Dec 2009
    Posts
    92
    Change onclick into onmouseclick in the top of your code, so

    bad:
    Code:
    window.onload=function() {
    document.getElementById('menu').onclick = active;

    good:
    Code:
    window.onload=function() {
    document.getElementById('menu').onmouseclick = active;

  7. #7
    Join Date
    Jul 2009
    Posts
    138

    Arrow

    Thank you so much !!!! but then the colours are not applied on the clicked link, so once I will click it it get back to normal ....?

  8. #8
    Join Date
    Jul 2009
    Posts
    138

    Arrow

    Quote Originally Posted by yomoore View Post
    Change onclick into onmouseclick in the top of your code, so

    bad:
    Code:
    window.onload=function() {
    document.getElementById('menu').onclick = active;

    good:
    Code:
    window.onload=function() {
    document.getElementById('menu').onmouseclick = active;
    This is working, but then the other part of the script is not working properly, link must stay in different colour once clicked, then if I am going to click another one the previous will be back to normal and the new one will be in different colour.

  9. #9
    Join Date
    Dec 2009
    Posts
    92
    You would have to use a cookie, if you want the browser to ''remember'' the previous click. When you come back from the link the code is shown as default.


    ps. ''onmousedown'' works better.
    Last edited by yomoore; 07-27-2011 at 05:25 AM.

  10. #10
    Join Date
    Jul 2009
    Posts
    138

    Arrow

    do you know where I can get some examples of the code? This should be so simple.

    If I got menu:

    ABC
    DEF

    Then once clicked ABC page will load and ABC will be in read all the time, then once pressed DEF the same apply for that as well but ABC will be back to normal + this effect should applied once mouse over the text.

  11. #11
    Join Date
    Dec 2009
    Posts
    92
    You can try CSS, as in: #menu li a:active{ your styling } or something like that. When you then return to the document the CSS active state will be there, then use js to take away the active state onclick some other link. Couldn't find a proper example for you but this is what I would do.

  12. #12
    Join Date
    Jul 2009
    Posts
    138

    Arrow

    do you know how to call it this effect (behaviour) so I can make a research in Google ?

  13. #13
    Join Date
    Dec 2009
    Posts
    92
    Try this: http://www.sohtanaka.com/web-design/...on/contact.htm

    It uses only CSS.

    (I wouldn't advise it if you planning to make some sort of tab-system with (i)frames because of the backspace which will take you to the previous tab instead of the previous url. You would be better of using Jquery with a cookie option.)

  14. #14
    Join Date
    Jul 2009
    Posts
    138

    Arrow

    thank you, unfortunately I am using iframes as well on those pages this code I presented above in the previous post really can not be adjusted to do what I will required? Regarding cookies and Jqueries I am not hat advanced to write my own. I can adjust existing one with custom styles ..etc

  15. #15
    Join Date
    Dec 2009
    Posts
    92
    Do you want the href to open as a new document(!COOKIE NEEDED) or do you want the href link(s) to open in an iframe(s)? (which is basically a tab-system)
    (Do the iframes on your page have anything to do with your links?)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles