javascript SocialHistory 检查访问者是否访问过某站点

时间:2021-05-28

window.onload=function(){
varsl=newSocialHistory();
alert(sl.doesVisit("/2007/12/24/adding-dynamic-contents-to-iframes
function createIframe() {
var iframe = document.createElement("iframe");
iframe.style.position = "absolute";
iframe.style.visibility = "hidden";

document.body.appendChild(iframe);

// Firefox, Opera
if(iframe.contentDocument) iframe.doc = iframe.contentDocument;
// Internet Explorer
else if(iframe.contentWindow) iframe.doc = iframe.contentWindow.document;

// Magic: Force creation of the body (which is null by default in IE).
// Also force the styles of visited/not-visted links.
iframe.doc.open();
iframe.doc.write('<style>');
iframe.doc.write("a{color: #000000; display:none;}");
iframe.doc.write("a:visited {color: #FF0000; display:inline;}");
iframe.doc.write('</style>');
iframe.doc.close();

// Return the iframe: iframe.doc contains the iframe.
return iframe;
}

var iframe = createIframe();

function embedLinkInIframe( href, text ) {
var a = iframe.doc.createElement("a");
a.href = href;
a.innerHTML = site;
iframe.doc.body.appendChild( a );
}

for( var site in sites ) {
var urls = sites[site];
for( var i=0; i<urls.length; i++ ) {
// You have to create elements in the scope of the iframe for IE.
embedLinkInIframe( urls[i], site );

// Automatically try variations of the URLS with and without the "www"
if( urls[i].match(/www\./) ){
var sansWWW = urls[i].replace(/www\./, "");
embedLinkInIframe( sansWWW, site );
} else {
// 2 = 1 for length of string + 1 for slice offset
var httpLen = urls[i].indexOf("//") + 2;
var withWWW = urls[i].substring(0, httpLen ) + "www." + urls[i].substring( httpLen );
embedLinkInIframe( withWWW, site );
}

}
}

var links = iframe.doc.body.childNodes;
for( var i=0; i<links.length; i++) {
// Handle both Firefox/Safari, and IE (respectively)
var displayValue = getStyle(links[i], iframe.doc, "display");
var didVisit = displayValue != "none";

if( didVisit ){visited[ links[i].innerHTML ] = true;}}remove( iframe );
return new (function(){var usedSites = [];for( var site in visited ){usedSites.push( site );}
// Return an array of visited sites.
this.visitedSites = function() {
return usedSites;
}

// Return true/false. If we didn't check the site, return -1.
this.doesVisit = function( site ) {
if( typeof( sites[site] ) == "undefined" )
return -1;
return typeof( visited[site] ) != "undefined";
}

var checkedSites = [];
for( var site in sites ){
checkedSites.push( site );
}
// Return a list of the sites checked.
this.checkedSites = function(){
return checkedSites;
}
})();
}

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章