Jump to content

innerHTML issues


Err

Recommended Posts

Hi folks.Long story short, I'm trying to edit a script with very little javascript knowledge, and I have no clue what I'm doing wrong (or just doing for that matter) perhaps you good JS folks can help me. :)Script:

<script type="text/javascript">    var BrowserDetect = {	init: function () {		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";		this.version = this.searchVersion(navigator.userAgent)			|| this.searchVersion(navigator.appVersion)			|| "an unknown version";		this.OS = this.searchString(this.dataOS) || "an unknown OS";	},	searchString: function (data) {		for (var i=0;i<data.length;i++)	{			var dataString = data[i].string;			var dataProp = data[i].prop;			this.versionSearchString = data[i].versionSearch || data[i].identity;			if (dataString) {				if (dataString.indexOf(data[i].subString) != -1)					return data[i].identity;			}			else if (dataProp)				return data[i].identity;		}	},	searchVersion: function (dataString) {		var index = dataString.indexOf(this.versionSearchString);		if (index == -1) return;		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));	},	dataBrowser: [		{			string: navigator.vendor,			subString: "Apple",			identity: "Safari"		},		{			prop: window.opera,			identity: "Opera"		},		{			string: navigator.vendor,			subString: "iCab",			identity: "iCab"		},		{			string: navigator.vendor,			subString: "KDE",			identity: "Konqueror"		},		{			string: navigator.userAgent,			subString: "Firefox",			identity: "Firefox"		},		{	// for newer Netscapes (6+)			string: navigator.userAgent,			subString: "Netscape",			identity: "Netscape"		},		{			string: navigator.userAgent,			subString: "MSIE",			identity: "Explorer",			versionSearch: "MSIE"		},		{			string: navigator.userAgent,			subString: "Gecko",			identity: "Mozilla",			versionSearch: "rv"		},		{ 	// for older Netscapes (4-)			string: navigator.userAgent,			subString: "Mozilla",			identity: "Netscape",			versionSearch: "Mozilla"		}	],	dataOS : [		{			string: navigator.platform,			subString: "Win",			identity: "Windows"		},		{			string: navigator.platform,			subString: "Mac",			identity: "Mac"		},		{			string: navigator.platform,			subString: "Linux",			identity: "Linux"		}	]};BrowserDetect.init();</script><script type="text/javascript">  document.write('<span style="color:blue;">' + BrowserDetect.browser + ' ' + BrowserDetect.version + ' / ' + BrowserDetect.OS + '</span>');</script>

The above code has 2 scripts, one to detect the browser/operting system (The long script) and another (short script near the bottom) to display the what the long script detected. My problem lies with the 2nd small script; I want to get rid of it and instead have an html tag in it's place like <span id="browser_os"></span>, I just want to simply elimiate the second script and use regular html tags in it's place; so then my next step was to edit the first script so I can add something that I can achieve that with. I came up with innerHTML for a solution, but I have no idea how I can implement it into this script. I have tried to do this by myself, but this is out of my league. Can one of you folks at least guide me into the right direction? If I had not made myself clear, please tell me so I can explain it in a more understanding way.

Link to comment
Share on other sites

Try this as your main, first, large code:

<script type="text/javascript">function chan() {  document.getElementById("osspan").innerHTML=BrowserDetect.browser+" "+BrowserDetect.version+" / "+BrowserDetect.OS}var BrowserDetect = {init: function () {this.browser = this.searchString(this.dataBrowser) || "An unknown browser";this.version = this.searchVersion(navigator.userAgent)|| this.searchVersion(navigator.appVersion)|| "an unknown version";this.OS = this.searchString(this.dataOS) || "an unknown OS";},searchString: function (data) {for (var i=0;i<data.length;i++) {var dataString = data[i].string;var dataProp = data[i].prop;this.versionSearchString = data[i].versionSearch || data[i].identity;if (dataString) {if (dataString.indexOf(data[i].subString) != -1)return data[i].identity;}else if (dataProp)return data[i].identity;}},searchVersion: function (dataString) {var index = dataString.indexOf(this.versionSearchString);if (index == -1) return;return parseFloat(dataString.substring(index+this.versionSearchString.length+1));},dataBrowser: [{string: navigator.vendor,subString: "Apple",identity: "Safari"},{prop: window.opera,identity: "Opera"},{string: navigator.vendor,subString: "iCab",identity: "iCab"},{string: navigator.vendor,subString: "KDE",identity: "Konqueror"},{string: navigator.userAgent,subString: "Firefox",identity: "Firefox"},{ // for newer Netscapes (6+)string: navigator.userAgent,subString: "Netscape",identity: "Netscape"},{string: navigator.userAgent,subString: "MSIE",identity: "Explorer",versionSearch: "MSIE"},{string: navigator.userAgent,subString: "Gecko",identity: "Mozilla",versionSearch: "rv"},{ // for older Netscapes (4-)string: navigator.userAgent,subString: "Mozilla",identity: "Netscape",versionSearch: "Mozilla"}],dataOS : [{string: navigator.platform,subString: "Win",identity: "Windows"},{string: navigator.platform,subString: "Mac",identity: "Mac"},{string: navigator.platform,subString: "Linux",identity: "Linux"}]};BrowserDetect.init();window.onload=chan;</script>

And put a span with the id of "osspan" anywhere on the page. :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...