Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Oliver Haag www.ohcon.de

« Newer Snippets
Older Snippets »
Showing 1-6 of 6 total  RSS 

Javascript Browser Check

// the navigator object stores the browser and additional secifications

<html><head><title>JS Browser Check</title></head><body>

<script type="text/javascript">
document.write("Your browser is " + navigator.appName);

if (navigator.appVersion.substring(0, 1) == "4")
  document.write("4th generation browser!");
  
document.write("patform/os:" + navigator.platform);
document.write("user agent data:" + navigator.userAgent);

if (navigator.cookieEnabled == true) {
  document.write("cookies enabled");
} else if (navigator.cookieEnabled == false) {
  document.write("no cookies.");
} else {
  document.write("cookies? No Info available.");
}

if (navigator.javaEnabled()) {
  document.write("java enabled.");
} else {
  document.write("java not available.");
}

if (navigator.language.indexOf("en") > -1) {
  document.write("language ins english");
}else if (navigator.language.indexOf("de") > -1) {
  document.write("language is german");
}

</script>

</body></html>

javasrcritpt email to avoid spam

// email is written with javascript to hide it aganst scanning.
// if javascript is off, the email is obfuscated
<script type="text/javascript" language=javascript>
<!--
name=('hugo');
at=('@');
domain=('mueller');
dot=('.');
ext=('de');
document.write('<a href="mailto:' + name + at + domain + dot + ext + '">' + name + at + domain + dot + ext + '<\/a>');
//-->
</script>
<noscript>hugo (at) mueller (dot) de</noscript>

change title with javascript

// change title with javascript

..
<title>original title</title>
..
<script type="text/javascript">
function changeTitle(title) { document.title = title; }
</script>
..
<input type='button' onclick='changeTitle("new title")' value='Change Title'/> 
..

check user agent with javascript

// check user agent

<a href="javascript:alert(navigator.userAgent)">User Agent</a>

Confirm Delete with javascript

// confirm() returns true or false
// submit() is only called on true and submits the form

<h1>Howto Confirm Delete</h1>
<form action="delete.html" method="post">
<input type="button" onclick="if (confirm('sure?')) submit();" value="delete">
</form>

change text

// javascript to change text

<script type="text/javascript">
function changeText(txt){
	document.getElementById('the_text').innerHTML = txt;
}
</script>
<p>Hello <b id='name'>World</b>. </p>
<input type='button' onclick='changeText("Oliver")' value='Change Text'/>
« Newer Snippets
Older Snippets »
Showing 1-6 of 6 total  RSS