| window.onload = function() { var sl = new SocialHistory(); alert(sl.doesVisit("m.survivalescaperooms.com")); } 如果用戶曾經(jīng)使用過m.survivalescaperooms.com,那么該函數(shù)就會(huì)返回真,否則返回假。 其實(shí)原理并不復(fù)雜,它利用了鏈接的 a:visited 偽類的屬性。首先在頁面上生成一個(gè)iframe,并在這個(gè)iframe中設(shè)置 a 和 a:visited 為不同的樣式。然后將網(wǎng)站的鏈接插入到 iframe 中。瀏覽器就會(huì)根據(jù)用戶的訪問歷史,為訪問過的鏈接設(shè)置 a:visited 的樣式。最后再獲得鏈接的最終樣式,如果是 a:visited,就可以認(rèn)為用戶訪問過該網(wǎng)站了。具體的實(shí)現(xiàn)方式可以參考源代碼。 這個(gè)腳本主要用于顯示社會(huì)性書簽的圖標(biāo),可以恰到好處地顯示用戶所使用的網(wǎng)站。但我擔(dān)心,這樣的做法是不是有盜取用戶隱私之嫌?雖然這個(gè)方法只能判斷用戶有無訪問特定的網(wǎng)站,并不能無限制地得到所有訪問歷史。 /* |
| * Social Limit - Only the social you care about. |
| * |
| * Enables your site to know which social bookmarking badges to display to your |
| * visitors. It tells you all social sites the user has gone to, or you can |
| * query for a specific one. |
| * |
| * For example: |
| * |
| * var sl = SocialHistory(); |
| * alert( sl.doesVisit("Digg") ); // Returns true/false, -1 if unknown. |
| * var listOfVisitedSites = sl.visitedSites(); |
| * var checkedSites = sl.checkedSites(); |
| * |
| * If you want to add more sites to check, you can pass that in as a dictionary |
| * to History: |
| * |
| * var more = { "Humanized": "http://humanized.com", |
| * "Azarask.in": ["http://azarask.in", "http://azarask.in/blog"] |
| * }; |
| * var sl = SocialHistory(more); |
| * alert( sl.doesVisit("Humanized") ); |
| * |
| * For a list of built-in sites, see the sites variable below. |
| * |
| * Copyright (c) 2008 Aza Raskin (http://azarask.in/blog) |
| * |
| * Permission is hereby granted, free of charge, to any person obtaining a copy 學(xué)習(xí)交流
熱門圖片
猜你喜歡的新聞
猜你喜歡的關(guān)注
新聞熱點(diǎn) 2024-04-27 13:35:46
2024-04-27 13:33:47
2024-04-24 22:53:44
2024-04-23 19:32:50
2024-04-23 19:25:50
2024-04-23 19:13:19
疑難解答 圖片精選 |