/    Sign up×
Community /Pin to ProfileBookmark

First post, two questions…

A forewarning here, I’m a complete JS noob, I’ve done websites for a while but never handled JS aside from snippets and the like. I know HTML, CSS, XML, SQL, PHP, Perl and a little ASP. I also code software in Delphi and C#, to give you some background in to what I do know, JS certainly not being one of them. I’ve been going through tutorials and eBooks etc. for now and learnt the basic syntax but I have gone no further, no complex scripts wrote – only simple things.

My question is a two parter. A.) Is it possible to disable a form, or simply the elements of a form, based on the response from an if statement rather than onclick etc. B.) Is the method I’m using in the code posted below efficient for selecting browser?

Here’s the code, I want to test see if the browser is Firefox which is best for my site, if not then if it is Internet Explorer and at this point to disable the form and tell them to download Firefox to gain access or an else to catch all other situations to simply recommend Firefox but nothing more.

[CODE]<script type=”text/javascript”>

if(navigator.appVersion == “5.0 (Windows)”) {

} else if(navigator.appVersion == “5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)”) {

document.write(“I refuse to allow anyone using Internet explorer to access this website. Please either visit on a seperate browser, I recommend Mozilla Firefox, or simply leave the website.”);
disable(true)

} else {
document.write(“Mozilla Firefox is the most appropriate browser for this website, please download it before continuing to get the full experience.”);

}
</script>[/CODE]

Thanks in advance for any help guys!

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@PadonakJun 15.2012 — try this

[CODE]<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>123</title>
<script type="text/javascript">
function checkIE(){
if(document.all){document.getElementById('fukIE').style.display='block';document.getElementById('notIE').style.display='none';}
}
window.onload=checkIE;
</script>
<style type="text/css">
body{text-align:center;font-family:Verdana,Arial;font-size:11px;background-color:#fff;color:#000;padding:0px;margin:15&#37; 0px 0px 0px;}
#fukIE{display:none;}
</style>
</head>
<body>
<div id="fukIE">I refuse to allow anyone using Internet explorer to access this website. Please either visit on a seperate browser, I recommend Mozilla Firefox, or simply leave the website.</div>
<div id="notIE">
<h2>Mozilla Firefox is the most appropriate browser for this website, please download it before continuing to get the full experience.</h2>
<form name="myform" action="">
<label for="username">Username: </label><input type="text" name="username" id="username" size="20"><br /><br />
<label for="pass">Password: </label><input type="text" name="pass" id="pass" size="20"><br /><br />
<input type="submit" value="Enter" />&nbsp;&nbsp;&nbsp;<input type="reset" value="Reset" />
</form>
</div>
</body>
</html>[/CODE]
Copy linkTweet thisAlerts:
@MycroftauthorJun 16.2012 — try this

&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="content-type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;123&lt;/title&gt;
&lt;script type="text/javascript"&gt;
function checkIE(){
if(document.all){document.getElementById('fukIE').style.display='block';document.getElementById('notIE').style.display='none';}
}
window.onload=checkIE;
&lt;/script&gt;
&lt;style type="text/css"&gt;
body{text-align:center;font-family:Verdana,Arial;font-size:11px;background-color:#fff;color:#000;padding:0px;margin:15% 0px 0px 0px;}
#fukIE{display:none;}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id="fukIE"&gt;I refuse to allow anyone using Internet explorer to access this website. Please either visit on a seperate browser, I recommend Mozilla Firefox, or simply leave the website.&lt;/div&gt;
&lt;div id="notIE"&gt;
&lt;h2&gt;Mozilla Firefox is the most appropriate browser for this website, please download it before continuing to get the full experience.&lt;/h2&gt;
&lt;form name="myform" action=""&gt;
&lt;label for="username"&gt;Username: &lt;/label&gt;&lt;input type="text" name="username" id="username" size="20"&gt;&lt;br /&gt;&lt;br /&gt;
&lt;label for="pass"&gt;Password: &lt;/label&gt;&lt;input type="text" name="pass" id="pass" size="20"&gt;&lt;br /&gt;&lt;br /&gt;
&lt;input type="submit" value="Enter" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;input type="reset" value="Reset" /&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
[/quote]


This does work for IE, thank-you! It also shows the message to recommend Firefox even when Firefox is being used, how can I fix this? If it isn't too much trouble, could you comment the code to explain it at each step, I can research each individual part but I imagine I'll get a bit of a better picture of how these tags are used in this context from your comments. I managed to implement it into my current page, I would simply like to understand what is going on. Thanks again!
Copy linkTweet thisAlerts:
@MycroftauthorJun 16.2012 — That does work for IE, thank-you! The message to recommend Firefox comes up even if you're on Firefox, how do you fix that? If it isn't too much trouble, could you comment the code so I can see what is going on? Thank-you.
Copy linkTweet thisAlerts:
@PadonakJun 16.2012 — here:

[CODE]<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>123</title>
<script type="text/javascript">
/* this function makes a shorthand for 'document.getElementById' - just to make the code shorter */
function doc(objID){return document.getElementById(objID);}

function checkIE(){
/* here we check to see if the browser does understand 'document.all' method.
if it does, that means we deal with IE, if it doesn't, the script will just skip the 'if(document.all)' statement */
if(document.all){doc.('fukIE').style.display='block';doc.('notIE').style.display='none';}
/* if navigator.userAgent has a substring 'Firefox' (no matter at which index)
we deal with Firefox and hide the message about Firefox downloading */
if(navigator.userAgent.indexOf('Firefox')!=-1){doc('ff').style.display='none';}
}
/* triggering the function after the page is fully loaded */
window.onload=checkIE;
</script>
<style type="text/css">
body{text-align:center;font-family:Verdana,Arial;font-size:11px;background-color:#fff;color:#000;padding:0px;margin:15&#37; 0px 0px 0px;}
#fukIE{display:none;}
</style>
</head>
<body>
<div id="fukIE">I refuse to allow anyone using Internet explorer to access this website.Please either visit on a seperate browser, I recommend Mozilla Firefox, or simply leave the website.</div>
<div id="notIE">
<h2 id="ff">Mozilla Firefox is the most appropriate browser for this website,<br />please <a href="http://www.mozilla.org/en-US/products/download.html?product=firefox-13.0.1&os=win&lang=en-US">download</a> it before continuing to get the full experience.</h2>
<form name="myform" action="">
<label for="username">Username: </label><input type="text" name="username" id="username" size="20"><br /><br />
<label for="pass">Password: </label><input type="text" name="pass" id="pass" size="20"><br /><br />
<input type="submit" value="Enter" />&nbsp;&nbsp;&nbsp;<input type="reset" value="Reset" />
</form>
</div>
</body>
</html>[/CODE]


(not good in the english language, my excuses)
×

Success!

Help @Mycroft spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...