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 8 of 8
  1. #1
    Regular Coder
    Join Date
    Nov 2011
    Posts
    154
    Thanks
    5
    Thanked 0 Times in 0 Posts

    link active state?

    How can you make a text link return from active to normal link state color after clicking on it? I had this working before but sme reason its not now. Not sure what's missing. Its working correctly in Chrome but not Firefox or IE. Here is page- http://resin.webs.com/new3.html . After clicking link, I want it to return to the normal link color (blue). Currently, it is staying red (active link color) even after the click.
    Last edited by resin; 06-14-2012 at 09:05 AM.

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    A link has active state either when the mouse cursor is over it and a mouse button is depressed or when the link has the focus and the enter key is depressed.

    To return a link from active state to either hover or focus state simply release the mouse button or enter key. To return it from hover state to normal move the mouse off of it or to return it from focus state to normal press the tab key.

    If it stays a different colour after being clicked then that would be caused by the visited state not the active state.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    Regular Coder
    Join Date
    Nov 2011
    Posts
    154
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Ok I figured out my problem with that..

    But there is one more issue I'm having with the active link state. In Firefox, the active state color doesn't come up at all when I click on the link, if I add this one line of script: document.onmousedown = function() {return false;} . I use this script to prevent text selection in Firefox (since the IE method doesn't work for FF). How can I prevent text selection and allow the active state color appear at the same time, in Firefox?

  • #4
    New Coder
    Join Date
    Apr 2012
    Posts
    67
    Thanks
    12
    Thanked 1 Time in 1 Post
    the page doesn't exist??

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by resin View Post
    Ok I figured out my problem with that..

    But there is one more issue I'm having with the active link state. In Firefox, the active state color doesn't come up at all when I click on the link, if I add this one line of script: document.onmousedown = function() {return false;} . I use this script to prevent text selection in Firefox (since the IE method doesn't work for FF). How can I prevent text selection and allow the active state color appear at the same time, in Firefox?
    You can't prevent text selection in any browser - since the code to do so can easily be disabled without affecting the rest of the page. That such code is pointless is clearly demonstrated by the fact that no major web site attempts to use it.

    Your simplest solution is to delete that code. That will in any case make your page more accessible as the code to prevent text selection also prevents some people from being able to view the content at all - unless they turn off JavaScript for the page.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #6
    Regular Coder
    Join Date
    Nov 2011
    Posts
    154
    Thanks
    5
    Thanked 0 Times in 0 Posts
    I want to prevent text selection not just to prevent my content being copied, but also because I will have several draggable objects placed around text and images, and it eliminates the possibility of accidently highlighting/selecting other text/objects that aren't meant to be draggable/functional.

    Would it be possible to exclude a particular div/element from being affected by document.onmousedown = function() {return false;} ? I tried document.getElementById("new").onmousedown = function() {return true;} but that didn't change anything. Is there another way?

  • #7
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Get rid of the call disabling it for the entire page and call the following function for the specific parts of the page where you must have it disabled.


    Code:
    disableMousedown = function(id) {
    document.getElementById(id).onmousedown = function() {return false;}
    }

    Better yet attach it using an event listener rather than an event handler so that you can remove it again when you don't need it disabled.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #8
    Regular Coder
    Join Date
    Nov 2011
    Posts
    154
    Thanks
    5
    Thanked 0 Times in 0 Posts
    This would work, but after thinking it over more, I really do need the text links themselves to be 'unhighlightable' also. It looks like you can still use onmousedown events on any particular div, when already having the "return false" in the script. So is there something I can place in a particular div's onmousedown that would change the link's color? I tried onmousedown="this.style.color='red'" but that didn't work. But is there something similar?


  •  

    Posting Permissions

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