Home > front end >  Checking Visited Websites with javascripts
Checking Visited Websites with javascripts

Time:01-04

Hello I am walking through the code which check if a user has visited websites before. and the code is as follows

<html>
    <body>
    <H1> Visited </H1>
    <ul id = "visited"></ul>
    <H1> Not visited</H1>
    <ul id ="notvisited"></ul>
        <script>
            var websites =[        
        "http://www.facebook.com",
        "http://www.instagram.com",
        "http://google.com",
        "http://twitter.com"
];
    for( var i = 0; i < websites.length; i  )
    {
        var link = document.createElement("a");
        var linebreak = document.createElement("br")
        link.href = websites[i]
        link.id = "id"   i  
        link.innerHTML = websites[i]   "&nbsp;" 
        document.write("<style>")
        document.write("#id"   i   ":visited{ color: #FF0000; }");
        document.write("</style>")
        document.body.appendChild(link) 
        document.body.appendChild(linebreak)
        var color = document.defaultView.getComputedStyle(link,null).getPropertyValue("color");
        document.write(color)
        document.body.appendChild(linebreak)
        if (color == "rgb(255, 0, 0)"){
        var item = document.createElement('li');
        item.appendChild(link);
        document.getElementById('visited').appendChild(item);

        }
         else {
        var item = document.createElement('li');
        item.appendChild(link);
        document.getElementbyId('notvisited').appendChild(item);
        }    
             }
        </script>
    </body>
</html>

When I check the colors of at the browser. it has changed visually but it has not change at document.write(color) showing rgb(0,0,238) still. So, the problem I am facing and question would like to ask are is as follow :

  1. Why does color does not change in value showing rgb(0,0,238) at document.write() although it changed visually?
  2. 'else' is not seemed to working here unless I replaced it with if (color == rgb(0,0,238) so why it happened there?

so please kindly help me the above problem. Many thanks in advance

CodePudding user response:

Checking the color of :visited in JavaScript has been a security/privacy vulnerability that was closed long ago. That is why the underlying values have not changed.

  •  Tags:  
  • Related