how to set link's "visited" property/pseudo-class without clicking on the link

Discussion in 'Javascript' started by friday13, Apr 27, 2007.

  1. friday13

    friday13 Guest

    Hi,

    I would like to set the link's "visited" pseudo-class with javascript
    without clicking on the link. My goal is to update the link's color
    (previously set in the CSS file) to be "visited" without actually
    clicking on the link and then clicking "back" in the browser.

    Does anyone know how? Here are the following things I've already
    tried to no avail:


    var obj = document.getElementById("idOfMyLink");

    //obj.visited=true; // NO
    //obj.style.visited=true; // NO
    //obj.click(); // NO, performs a click and takes me away from
    current page

    /*
    // Setting the src of an iframe on the same page, trying to
    "stuff" this URL into browser's "History"

    var theFrame = document.getElementById("myiframe");
    theFrame.src = obj.href;

    // NO. The iframe does go to correct URL, but the link's color
    doesn't update.
    */

    Any ideas?

    Thanks for your help!
     
    friday13, Apr 27, 2007
    #1
    1. Advertising

  2. friday13

    friday13 Guest

    On Apr 27, 3:23 pm, friday13 <> wrote:
    > Hi,
    >
    > I would like to set the link's "visited" pseudo-class with javascript
    > without clicking on the link. My goal is to update the link's color
    > (previously set in the CSS file) to be "visited" without actually
    > clicking on the link and then clicking "back" in the browser.
    >
    > Does anyone know how? Here are the following things I've already
    > tried to no avail:
    >
    > var obj = document.getElementById("idOfMyLink");
    >
    > //obj.visited=true; // NO
    > //obj.style.visited=true; // NO
    > //obj.click(); // NO, performs a click and takes me away from
    > current page
    >
    > /*
    > // Setting the src of an iframe on the same page, trying to
    > "stuff" this URL into browser's "History"
    >
    > var theFrame = document.getElementById("myiframe");
    > theFrame.src = obj.href;
    >
    > // NO. The iframe does go to correct URL, but the link's color
    > doesn't update.
    > */
    >
    > Any ideas?
    >
    > Thanks for your help!


    This is not a self-"bump"... just a follow-on question with a
    possible work-around.


    So this is a hack, but a way to SORT OF get the link "visited" is is
    to open a new window with that URL:

    var win = window.open( url,'mywindow','width=100,height=200');

    And then close it right away.

    win.close();

    But the link-color is NOT updated until I refresh the page.

    So this generates a 2nd question:

    Is there any way to FORCE the link to update its color??

    Thanks.
     
    friday13, Apr 28, 2007
    #2
    1. Advertising

  3. friday13

    Guest

    On Apr 28, 12:23 am, friday13 <> wrote:
    > Hi,
    >
    > I would like to set the link's "visited" pseudo-class with javascript
    > without clicking on the link. My goal is to update the link's color
    > (previously set in the CSS file) to be "visited" without actually
    > clicking on the link and then clicking "back" in the browser.
    >
    > Does anyone know how? Here are the following things I've already
    > tried to no avail:
    >
    > var obj = document.getElementById("idOfMyLink");
    >
    > //obj.visited=true; // NO
    > //obj.style.visited=true; // NO
    > //obj.click(); // NO, performs a click and takes me away from
    > current page
    >
    > /*
    > // Setting the src of an iframe on the same page, trying to
    > "stuff" this URL into browser's "History"
    >
    > var theFrame = document.getElementById("myiframe");
    > theFrame.src = obj.href;
    >
    > // NO. The iframe does go to correct URL, but the link's color
    > doesn't update.
    > */
    >
    > Any ideas?
    >
    > Thanks for your help!


    You could define a class in the CSS then just change the class of the
    link ;p
     
    , Apr 28, 2007
    #3
  4. friday13

    friday13 Guest

    On Apr 27, 5:00 pm, wrote:
    > On Apr 28, 12:23 am, friday13 <> wrote:
    >
    >
    >
    >
    >
    > > Hi,

    >
    > > I would like to set the link's "visited" pseudo-class with javascript
    > > without clicking on the link. My goal is to update the link's color
    > > (previously set in the CSS file) to be "visited" without actually
    > > clicking on the link and then clicking "back" in the browser.

    >
    > > Does anyone know how? Here are the following things I've already
    > > tried to no avail:

    >
    > > var obj = document.getElementById("idOfMyLink");

    >
    > > //obj.visited=true; // NO
    > > //obj.style.visited=true; // NO
    > > //obj.click(); // NO, performs a click and takes me away from
    > > current page

    >
    > > /*
    > > // Setting the src of an iframe on the same page, trying to
    > > "stuff" this URL into browser's "History"

    >
    > > var theFrame = document.getElementById("myiframe");
    > > theFrame.src = obj.href;

    >
    > > // NO. The iframe does go to correct URL, but the link's color
    > > doesn't update.
    > > */

    >
    > > Any ideas?

    >
    > > Thanks for your help!

    >
    > You could define a class in the CSS then just change the class of the
    > link ;p- Hide quoted text -
    >
    > - Show quoted text -


    @tsukasa

    Ok, so how do I know the "color" value of visited links for that page?

    I'm trying to write a greasemonkey script that could apply to pages
    that I don't own/create.

    Question 3:

    How do I get the value of "a:visited" that is defined in a CSS file?
    Or what if it's not [user is using the regular blue/purple combination
    from browser?

    Thanks.
     
    friday13, Apr 28, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luigi Donatello Asero

    Class selector, ID selectors and link pseudo-classes

    Luigi Donatello Asero, Jun 4, 2005, in forum: HTML
    Replies:
    4
    Views:
    529
    Luigi Donatello Asero
    Jun 4, 2005
  2. Luigi Donatello Asero
    Replies:
    1
    Views:
    412
    Luigi Donatello Asero
    Jun 4, 2005
  3. Peter J Ross
    Replies:
    5
    Views:
    548
    Peter J Ross
    Sep 2, 2007
  4. Chad
    Replies:
    8
    Views:
    212
  5. Net
    Replies:
    4
    Views:
    225
Loading...

Share This Page