webForumDet fria alternativet

Hjälp med referrer script i framesets

3 svar · 206 visningar · startad av echoSwe

echoSweMedlem sedan nov. 20041 467 inlägg
#1

Tjena!

Jag skulle vilja ha hjälp med de rader som jag har kommenterat //?? på :). Inget speciellt alltså, utan bara för att lära mig. Detta är netstads script, alltså copyrighted, men jag använder det bara för att lära mig, så klaga inte.

Här kommer det.

// JavaScript Document
function plugNS() //scanning for plugins in NS
{
	var b = 1;
	var o = 0;
	var p = new Array("Shockwave Flash",
					  "Shockwave for Director",
					  "RealPlayer",
					  "QuickTime",
					  "VivoActive",
					  "LiveAudio",
					  "VRML",
					  "Dynamic HTML Binding",
					  "Windows Media Services");
	var np = navigator.plugins;
	for (var x=0; x < p.length; x++) //looping through plugins array
	{
		//looping through all installed plugins
		for (var i=0; i<np.length; i++) 
			//if there is a plugin installed that is in pre-made array, but then what??!?!?
			if(np[i].name.indexOf(p[x]) >= 0) 
				o|=b; //??
		b *= 2; //??
	}
	return o;
}

function plugIE() //scanning for plugins in IE
{
	if(!document.body) document.write('<body>'); //??
	var db = document.body;
	var o=0; //??
	var b=1; //??
	var p = new Array("D27CDB6E-AE6D-11CF-96B8-444553540000", //this is IE's way of marking specific plug-ins
					"2A202491-F00D-11CF-87CC-0020AFEECF20",
					"23064720-C4F8-11D1-994D-00C04F98BBC9","","","",
					"90A7533D-88FE-11D0-9DBE-0000C0411FC3",
					"9381D8F2-0288-11D0-9501-00AA00B911A5",
					"22D6F312-B0F6-11D0-94AB-0080C74C7E95"
	);
	db.addBehavior("#default#clientcaps"); //?? - adds a behavior to the document body
	for(var i=0; i < p.length; i++) //looping through all the plugins
	{	
		//checking if there is a plugin in this position of the array
		if (p[i]) 
			//checking if this component is installed, but then what??!?!?
			if (db.isComponentInstalled("{"+p[i]+"}","componentid")) o|=b; 
		b*=2;
	}
	return o;
}

function nedstatbasic (id, options) //id = personal id for this counter; options = 1 if frameset, 0 is not
{
	var n = navigator;
	var ver = n.appVersion;
	var d=document;
	var verIE = parseInt(ver.substring(ver.indexOf("MSIE")+5,ver.indexOf("MSIE")+6));
	
	if(verIE>0) ver = verIE;
	else ver=parseInt(ver);
	
	/* HERE IS WHAT I WANT */
	var u = "http://m1.nedstatbasic.net/n?id="+id; //declares the query string variable
	var r; //r is the shit! (i.e. it gets you the referrer outside a frameset)
	if(options&1) r = d.referrer; //if options is filled out, but it's 0; not a frameset
	else r = top.document.referrer; //if you are using a frameset - the shit!
	
	if(!(options&2)) //??
	{
		//rc new referrer variable
		var rc = r; 
		
		//sets the index of questionmark in the referrer variable to i
		var i = rc.indexOf('?');
		
		//there was a questionmark, then change the referrer var to the URI without the querystring(s) attached
		if(i>=0) rc = rc.substring(0,i);
			i = rc.lastIndexOf('/'); //get the address without the slash in the end, I think
		if(i>=0) //??
			rc = rc.substring(0, i+1); //??
		var l= '' +d.location; //create a variable location, and set it to current page
		if(l.indexOf(rc)==0) r=''; //if the current location is the referrer, then remove the referrer string altogether
	}
	//u is what they append to the query string. If there is a referrer. They append it to the r querystring
	if(r && (r!=d.location)) u += "&r=" + escape(r); 
	
	//if netscape (& gecko engine?) is used
	if((n.appName=="Netscape" && ver>=3)) u += "&p=" + plugNS(); 
	
	//if IE is used, version > 5 and in windows, and not opera, then append plugin string
	if(verIE >= 5 && n.appVersion.indexOf('Win') >= 0 && n.userAgent.indexOf('Opera')<0) u+="&p=" + plugIE(); 
	if(ver>=4)
	{
		var s = screen;
		var w = s.width;
		var h = s.height;
		var c = s.colorDepth;
		if(w) u += "&w=" + w; //if a width exist
		if(h) u += "&h=" + h; //if a height exist
		if(c) u += "&c=" + c; //if color depth is gotten
	}
	
	//this line won't work in XHTML 1.1 (document.write)
	d.write('<a target=_blank href="http://www.nedstatbasic.net/stats?' 
			+ id 
			+ '"><img src="'+u+'" border=0 width=18 height=18 alt="Nedstat Basic - Free web site statistics"></a>');
}
echoSweMedlem sedan nov. 20041 467 inlägg
#2

Alltså, kopiera in det i DW eller nåt som färgar koden så ser ni att det är högst 4-5 rader som jag inte fattar... Så bli inte rädda för all text... ;)

dectgapMedlem sedan sep. 20021 542 inlägg
#3

Med lite förklarande kommentarer:

// JavaScript Document
function plugNS() //scanning for plugins in NS
{
	var b = 1;
	var o = 0;
	var p = new Array("Shockwave Flash",
					  "Shockwave for Director",
					  "RealPlayer",
					  "QuickTime",
					  "VivoActive",
					  "LiveAudio",
					  "VRML",
					  "Dynamic HTML Binding",
					  "Windows Media Services");
	var np = navigator.plugins;
	for (var x=0; x < p.length; x++) //looping through plugins array
	{
		//looping through all installed plugins
		for (var i=0; i<np.length; i++) 
			//if there is a plugin installed that is in pre-made array, but then what??!?!?
			if(np[i].name.indexOf(p[x]) >= 0)
				o|=b; // o|=b är samma sak som o=o|b, d.v.s. bitvis OR på talen o och b.
				      // Om rätt plugin finns installerad sätter vi den x:te biten i talet o
				      // till 1, annars sätter vi den till 0.
		b *= 2; // b *= 2 är samma sak som b = b*2, d.v.s. multiplicera b med 2.
		        // Om du är van vid bitvisa operationer hade det kanske varit mer logiskt att
		        // skriva b<<1, d.v.s. vänstershifta b ett steg.
	}
	return o;
}

function plugIE() //scanning for plugins in IE
{
	if(!document.body) document.write('<body>'); // Om document.body inte finns, d.v.s. vi har inte skapat
	                                             // något body-element än, så skapa det genom att skriva
	                                             // ut body-taggen.
	var db = document.body;
	var o=0; //??
	var b=1; //??
	var p = new Array("D27CDB6E-AE6D-11CF-96B8-444553540000", //this is IE's way of marking specific plug-ins
					"2A202491-F00D-11CF-87CC-0020AFEECF20",
					"23064720-C4F8-11D1-994D-00C04F98BBC9","","","",
					"90A7533D-88FE-11D0-9DBE-0000C0411FC3",
					"9381D8F2-0288-11D0-9501-00AA00B911A5",
					"22D6F312-B0F6-11D0-94AB-0080C74C7E95"
	);
	db.addBehavior("#default#clientcaps"); // adds a behavior to the document body
	                                       // Hämtar information om installerade plugins i IE.
	                                       // Läs mer: [url]http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/methods/addbehavior.asp[/url]
	                                       // [url]http://msdn.microsoft.com/library/default.asp?url=/workshop/author/behaviors/reference/reference.asp[/url]
	                                       // [url]http://msdn.microsoft.com/library/default.asp?url=/workshop/author/behaviors/reference/behaviors/clientcaps.asp[/url]
	for(var i=0; i < p.length; i++) //looping through all the plugins
	{	
		//checking if there is a plugin in this position of the array
		if (p[i]) 
			//checking if this component is installed, but then what??!?!?
			if (db.isComponentInstalled("{"+p[i]+"}","componentid")) o|=b; 
		b*=2;
	}
	return o;
}

function nedstatbasic (id, options) //id = personal id for this counter; options = 1 if frameset, 0 is not
{
	var n = navigator;
	var ver = n.appVersion;
	var d=document;
	var verIE = parseInt(ver.substring(ver.indexOf("MSIE")+5,ver.indexOf("MSIE")+6));
	
	if(verIE>0) ver = verIE;
	else ver=parseInt(ver);
	
	/* HERE IS WHAT I WANT */
	var u = "http://m1.nedstatbasic.net/n?id="+id; //declares the query string variable
	var r; //r is the shit! (i.e. it gets you the referrer outside a frameset)
	if(options&1) r = d.referrer; //if options is filled out, but it's 0; not a frameset
	else r = top.document.referrer; //if you are using a frameset - the shit!
	
	if(!(options&2)) // Bitvis AND på andra biten (eftersom 2(bas 10) = 10(bas 2)
	                 // Enligt kommentaren i funktionshuvudet kan options vara 1 eller 0, så
	                 // jag förstår inte riktigt meningen med if-satsen.
	{
		//rc new referrer variable
		var rc = r; 
		
		//sets the index of questionmark in the referrer variable to i
		var i = rc.indexOf('?');
		
		//there was a questionmark, then change the referrer var to the URI without the querystring(s) attached
		if(i>=0) rc = rc.substring(0,i);
			i = rc.lastIndexOf('/'); //get the address without the slash in the end, I think
		if(i>=0) //??
			rc = rc.substring(0, i+1); // Plocka ut top.document.referrer utan query-string
		var l= '' +d.location; //create a variable location, and set it to current page
		if(l.indexOf(rc)==0) r=''; //if the current location is the referrer, then remove the referrer string altogether
	}
	//u is what they append to the query string. If there is a referrer. They append it to the r querystring
	if(r && (r!=d.location)) u += "&r=" + escape(r); 
	
	//if netscape (& gecko engine?) is used
	if((n.appName=="Netscape" && ver>=3)) u += "&p=" + plugNS(); 
	
	//if IE is used, version > 5 and in windows, and not opera, then append plugin string
	if(verIE >= 5 && n.appVersion.indexOf('Win') >= 0 && n.userAgent.indexOf('Opera')<0) u+="&p=" + plugIE(); 
	if(ver>=4)
	{
		var s = screen;
		var w = s.width;
		var h = s.height;
		var c = s.colorDepth;
		if(w) u += "&w=" + w; //if a width exist
		if(h) u += "&h=" + h; //if a height exist
		if(c) u += "&c=" + c; //if color depth is gotten
	}
	
	//this line won't work in XHTML 1.1 (document.write)
	d.write('<a target=_blank href="http://www.nedstatbasic.net/stats?' 
			+ id 
			+ '"><img src="'+u+'" border=0 width=18 height=18 alt="Nedstat Basic - Free web site statistics"></a>');
}

Om du inte har någon aning om vad bitvisa operationer innebär kan du läsa mer här:
http://susning.nu/Och#2
http://susning.nu/Eller

echoSweMedlem sedan nov. 20041 467 inlägg
#4

Tack så mycket.

Genererad på 385 ms · cache AV · v20260730165559-full.f96bc7eb