Javascript to get URL

Discussion in 'JavaScript' started by chtnverma, Aug 4, 2010.

  1. #1
    Hi all

    I have a relatively easy issue and need your suggestions..

    I am to give a demo where I identify certain details about a particular webpage viewed by the user (who will use my machine). For the system I've built using Php and Java, I just need the URL that user is viewing. Till now I have been feeding the URL manually but now need to have an automated way to get the URL of all pages the user opens. The opened websites are like www.youtube.com (and obviously not owned by me)

    I tried placing a Squid proxy and looking at the received requests but I get many requests other than the URL too and the proxy has no way of identifying which one corresponds to the URL and which ones are sent by other stuff in the page.

    Since it is my machine that I'll be using for the demo, I am allowed to have javascripts on my browser (Firefox). I need some advice on any javascripts that may help me do t
    this. Appreciate any help

    thanks! - C
     
    chtnverma, Aug 4, 2010 IP
  2. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    I guess you could easily do this using a windows based app, that accesses the history files of your browser. But I am uncertain of where FireFox locates these.
     
    camjohnson95, Aug 5, 2010 IP
  3. chtnverma

    chtnverma Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks camjohnson95. Yes, I am looking into that too as a possible solution. Just that I have to process the URLs in real-time demo and felt using thought JS would be a cleaner option.
     
    chtnverma, Aug 5, 2010 IP
  4. swashata

    swashata Member

    Messages:
    86
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #4
    swashata, Aug 8, 2010 IP
  5. chtnverma

    chtnverma Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks for replying swashata. What you directed me to would help me set up a webpage which can show URLs the user (who opens my webpage) has visited. I am just looking for an automated method to get URLs of pages that I open on my PC (with Firefox) as soon as I open any website or click on any link.
    Thanks again, I appreciate you replying to this thread. If you have further suggestions, pls let me know :)
     
    chtnverma, Aug 8, 2010 IP
  6. swashata

    swashata Member

    Messages:
    86
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #6
    Something like this would help you!
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title>asdasd</title>
    
    </head>
    <body>
        <script type="text/javascript">
    <!--
    /*
    NAME: JavaScript History Thief
    AUTHOR: Jeremiah Grossman
    
    BSD LICENSE:
    Copyright (c) 2006, WhiteHat Security, Inc.
    All rights reserved.
    
    Redistribution and use in source and binary forms, with or without 
    modification, are permitted provided that the following conditions are met:
    
    * Redistributions of source code must retain the above copyright notice, 
    this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice, 
    this list of conditions and the following disclaimer in the documentation 
    and/or other materials provided with the distribution.
    * Neither the name of the WhiteHat Security nor the names of its contributors 
    may be used to endorse or promote products derived from this software 
    without specific prior written permission.
    
    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
    ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
    THE POSSIBILITY OF SUCH DAMAGE.
    */
    
    
    /* A short list of websites to loop through checking to see if the victim has been there. Without noticable performance overhead, testing couple of a couple thousand URL's is possible within a few seconds. */
    var websites = [
    	"http://ha.ckers.org/blog/",
    	"http://login.yahoo.com/",
    	"http://mail.google.com/",
    	"http://mail.yahoo.com/",
    	"http://my.yahoo.com/",
    	"http://sla.ckers.org/forum/",
    	"http://slashdot.org/",
    	"http://www.amazon.com/",
    	"http://www.aol.com/",
    	"http://www.apple.com/",
    	"http://www.bankofamerica.com/",
    	"http://www.bankone.com/",
    	"http://www.blackhat.com/",
    	"http://www.blogger.com/",
    	"http://www.bofa.com/",
    	"http://www.capitalone.com/",
    	"http://www.cgisecurity.com/",
    	"http://www.chase.com/",
    	"http://www.citibank.com/",
    	"http://www.cnn.com/",
    	"http://www.comerica.com/",
    	"http://www.e-gold.com/",
    	"http://www.ebay.com/",
    	"http://www.etrade.com/",
    	"http://www.flickr.com/",
    	"http://www.google.com/",
    	"http://www.hsbc.com/",
    	"http://www.icq.com/",
    	"http://www.live.com/",
    	"http://www.microsoft.com/",
    	"http://www.microsoft.com/en/us/default.aspx",
    	"http://www.msn.com/",
    	"http://www.myspace.com/",
    	"http://www.passport.net/",
    	"http://www.paypal.com/",
    	"http://www.rsaconference.com/2007/US/",
    	"http://www.salesforce.com/",
    	"http://www.sourceforge.net/",
    	"http://www.statefarm.com/",
    	"http://www.usbank.com/",
    	"http://www.wachovia.com/",
    	"http://www.wamu.com/",
    	"http://www.wellsfargo.com/",
    	"http://www.whitehatsec.com/home/index.html",
    	"http://www.wikipedia.org/",
    	"http://www.xanga.com/",
    	"http://www.yahoo.com/",
    	"http://www2.blogger.com/home",
    	"https://banking.wellsfargo.com/",
    	"https://commerce.blackhat.com/",
    
    
    ];
    var visited_url = new Array;
    var n_visited_url = new Array;
    /* Loop through each URL */
    
    for (var i = 0; i < websites.length; i++) {
    	
    	/* create the new anchor tag with the appropriate URL information */
    	var link = document.createElement("a");
    	link.id = "id" + i;
    	link.href = websites[i];
    	link.innerHTML = websites[i];
    
    	/* create a custom style tag for the specific link. Set the CSS visited selector to a known value, in this case red */
    	document.write('<style>');
    	document.write('#id' + i + ":visited {color: #FF0000;}");
    	document.write('</style>');
    	
    	/* quickly add and remove the link from the DOM with enough time to save the visible computed color. */
    	document.body.appendChild(link);
    	var color = document.defaultView.getComputedStyle(link,null).getPropertyValue("color");
    	document.body.removeChild(link);
    	
    	/* check to see if the link has been visited if the computed color is red */
    	if (color == "rgb(255, 0, 0)") { // visited
    	
    		/* add the link to the visited list */
    		visited_url.push(websites[i]);
    		
    	} else { // not visited
    	
    		/* add the link to the not visited list */
    		n_visited_url.push(websites[i]);
    		
    	} // end visited color check if
    
    } // end URL loop
    
    alert(visited_url);
    
    // -->
    
        </script>
    </body>
    </html>
    
    HTML:
    Note that you have the variable array visited_url with the links to the visited sites! You can use it to do whatever you like! The thing is there is not straight forward way to get the history from a browser using JS [As far as I know]...
    So you need to provide the list!
     
    swashata, Aug 9, 2010 IP