Need a very specific Javascript… to noob to write it:( :p

August 7th, 2016

Ok here goes,
I need a javascript, this script needs to do the following:
When a users comes on my site, this script checks if the user is using Mozilla Firefox 2.0 and if he does, the script does nothing, but when the user doesnt use firefox, i need a error window that says, “you need mozilla firefox 2.0 to view this page, please update” then the user has 2 buttons, 1 with a link to Firefox2.0 setup or something and a button with continue annyway.
i would realy apriciate help, i allready have an Browser detection script (downloaded) and i understand basic JS, but this is way over my head :p.
this is the browser detection script i am using to write the user version on my page (its in dutch):

var controle = navigator.userAgent.toLowerCase();
var OS,browser,versie,de_string;
function browsernaam(string)
{plaats = controle.indexOf(string) + 1; de_string = string; return plaats;}
if (browsernaam('konqueror')){browser = "Konqueror";OS = "Linux";}
else if (browsernaam('safari')) browser = "Safari"
else if (browsernaam('omniweb')) browser = "OmniWeb"
else if (browsernaam('opera')) browser = "Opera"
else if (browsernaam('webtv')) browser = "WebTV";
else if (browsernaam('icab')) browser = "iCab"
else if (browsernaam('msie')) browser = "Microsoft Internet Explorer"
else if (browsernaam('firefox')) browser = "Firefox"
else if (!browsernaam('compatible')){browser = "Netscape Navigator"; versie = controle.charAt(82) + controle.charAt(83) + controle.charAt(84);}
else browser = "een onbekende browser";
// versie detecteren
if (!versie)
versie = controle.charAt(plaats + de_string.length)+ controle.charAt(plaats + de_string.length +1)+ controle.charAt(plaats + de_string.length +2)
// OS detecteren
if (!OS){
if (browsernaam('linux')) OS = "Linux";
else if (browsernaam('x11')) OS = "Unix";
else if (browsernaam('mac')) OS = "Mac";
else if (browsernaam('win')) OS = "Windows";
else OS = "een onbekend systeem";}
// java ondersteuning
if(navigator.javaEnabled())java = "ondersteund";
else java = "niet ondersteund";
// huidige resolutie
w = screen.width;
h = screen.height;
resolutie = w + " x " + h;
// kleurendiepte (bit)
color = window.screen.colorDepth;
// accepteert cookies
if(navigator.cookieEnabled)cookies = "geaccepteerd";
else cookies = "niet geaccepteerd";

here is the site with the script in action www.viesign.com
hope annybody knows how to do this.
Greets

Answer #1
I changed a bit in this script to help you understand it better.
http://~ Dead file host ~/files/76915968/browser.html
Try Aptana to write JavaScripts, it shows the possible functions and helps debugging scripts.
There are 3 functions:
BrowserIs(browser)
This function checks if the given browser is used by the client.
GetBrowserVersion()
Gets the version of the browser.
There might be a better way to check this.
CheckBrowser()
Checks what browser the client is using and stores the name in a variable.
Examples
I used this in the body.onload of the file.
It shows an alert with the browsername and the version.
CheckBrowser(); alert(‘You are using ‘ + browser + ‘\n\r’ + ‘version ‘ + GetBrowserVersion());
Answer #2
Well, thank you, but al your work is pretty much the same as what i allready had. Thnx annyway
Answer #3
I don’t really understand why you need such a long script. If you just want to block the site from non Firefox 2.0 users just do something like this:
<script language="javascript">
// Written by @
var f = navigator.userAgent.toLowerCase();
var d = navigator.userAgent.lastIndexOf("/")+1;
var s = f.charAt(d);
var n = d*1;
if ((n>=2) || f.indexOf("firefox") != -1){
   document.write ("FF 2 or above");
}else{
   document.write ("not FF 2");
}
</script>

The script makes it very easy to know whether the user is using FF 2 or not. If the client is using FF 2 or above the script will print “FF 2 or above” to the screen. Otherwise “not FF 2” will be printed. You can use whatever conditions you like in the if statement. Good luck mate ^_^
Answer #4
thnx, nice solution
Answer #5
You’re welcome mate. Don’t forget that since Javascript is best used as client side scripting you’re better off looking for the most efficient way around a problem, just a tip
Good luck mate ^_^

 

| Sitemap |