Search code examples
javascriptinternet-explorerinternet-explorer-9browser-history

Get user's most visited sites in IE9 with javascript?


I'm making a html file thats going to run locally in case it matters. It only needs to run on IE9 but it would be nice if it works in other browsers. I need to get the user's most visited sites so I can display them kind of like the default new tab page in IE9. Also it would be nice if I could get the recent history as well. Are these possible or do I have to use a plug-in?


Solution

  • Although you can't get the "most visited" but you can get those that have been visited.

    The procedure is that you need to prepare a long list of domains. Then in your page, load an iframe that will put these links on the DOM. The iframe is needed so that you can load the page without any style at all, away from your main page. That way we can see the default link colors which we will use.

    now you have a blank document in an iframe with a bunch of links, what's next? you let JavaScript iterate through the links, check if they are blue or purple, catch my drift? It means that if that link's color is blue, it has not been visited. If it's purple, then it's visited. and since your iframe and the parent page are of the same domain, the parent can get the "statistics" in the iframe.

    the disadvantages of this method are:

    1. If the user changes the default colors of visited and non-visited links in the browser itself. You are hard-coding the color. if it changes for that user, you can't get any good stats.

    2. You are limited to your list of links. Although you can add.

    3. It exhausts the DOM. say you have 1000 urls to check, you'd have to append 1000 <a> tags to a blank <iframe> and let JavaScript walk through all of them.

    4. Exact links. If you read news in yahoo.com/news/etc...., it's not the same as yahoo.com thus it won't be picked up. Ideally, you only need to list top level domains.

    5. You don't get "times visited". You only know what domains were visited, but not how frequently. However, what you can do is when in your "New Tab Page", you can store in a cookie what links the user clicks. Example if you have google.com in your "New Tab Page", if the user clicks on it, increment a count for Google in the cookie and then go to google. the next time your "New Tab Page" loads, read that cookie and continue the count.