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 11-20 of 30 total

css learns to calculate

// only css3.0, preliminary

div#left_half  {
  float:left;
  width:calc(50% - 8px);
}

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>

reformat unsigned lists (bullet lists)

// unsigned list look the same in firefox and internet explore
// but firefox uses padding and ie uses margin to indent
// so if you want to eliminate the indent you mat set both

// here the top margin is negative too
// so the bullet list is written directly under the text
// and the bottom-margin of the p-tag can remain (needet elsewhere)
ul {
	padding-left: 15px;
	margin-left: 0px;
	margin-top: -10px;
	margin-bottom: 10px;
}

avoid visible whitespace in html

// if you want a line break and want to indent your html code
// but the browser makes problems with the whitespace
// make the whitespace a comment

//example
<div id="topimages">
	<image class="left" src="image/left.jpg"><!--
	--><image class="left" src="image/mid.jpg"><!--
	--><image class="right" src="image/right.jpg">
</div><!--topimages-->

set width and padding without ccs browser hack

// firefox an internet explorer handle padding in div-elements with width differently
// you don't need a css browser hack, you can use two div-elements insteas
// the outer-div handles width
// the inner div handles padding

//html
<div id="left_text">
	<div class="paddingbox">
		<p>loem ipsum dolor ...</p>
	</div>
</div><!--left_text-->


//css
//padding: top right, bottom, left;
#left_text {
	width: 208px;
	float: left;
}
div.paddingbox {
	padding: 4px 8px 4px 8px;
}

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'/> 
..

IdGenerator in java

// IdGenerator

public class IdGenerator {
	
	private long maxId; 
	
	public IdGenerator(long start) {
		maxId = start;
	}
	
	public long getNextId () {
		return ++maxId;
	}

} // IdGenerator

save Data with db4o

// save Data with db4o

import com.db4o.Db4o;
import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;
import com.db4o.query.Query;
...

public class DbUtil {

  /**
  * save someObject to DB
  */
  public static void saveData(SomeClass someObject, String DbFilename) {
    ObjectContainer db=Db4o.openFile(DbFilename);
    try {
      db.set(idGenerator);
    }
    finally {
      db.close();
    }
  } //saveData(SomeClass ..)

  ..

} //DbUtil

check user agent with javascript

// check user agent

<a href="javascript:alert(navigator.userAgent)">User Agent</a>
« Newer Snippets
Older Snippets »
Showing 11-20 of 30 total