document.getElementById in IE7

2009-07-16 22:00:13
0 comment(s)

Given the following code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<title>IE7 getElementById() test</title>
	<meta http-equiv="content-type" content="text/html;charset=utf-8" />
	<meta http-equiv="Content-Style-Type" content="text/css" />
	<meta name="description" content="Internet Explorer 7 getElementById() test" />
</head>
<body>
	<form action="index.php" method="post">
		<div>
			<label for="description">Description: </label>
<textarea rows="10" cols="82" name="foo" id="description">Write some description here...</textarea>
<button type="submit">Save</button> </div> </form> <script type="text/javascript"> <!-- var obj = document.getElementById('description'); document.write('getElementById() returned a ' + obj.tagName + ' node'); //--> </script> </body> </html>

Can you guess what the output will be? Yes, for most of the cases it will be "TEXTAREA". But not for IE7 (and older)! According to the docs it will be "META". If you want to be Internet Explorer 7 compatible, you should never-ever call any object you want to access from JavaScript "description".

Tags: msie javascript getelementbyid

How to detect multiple window usage in JS

2009-03-01 00:15:26
3 comment(s)

When designing a web application, one should keep tabbed browsing in mind, because this is one of the greatest features in browser-history. So great that even Microsoft had to implement it in IE!

But sometimes using an application in multiple windows or tabs just doesn't make much sense, and can be expensive. For example a chat or IM application (like Meebo) polls the server nearly in every seconds, and doing that simultaneously in more tabs or windows is simply wasting resources on both server and client side. In such situations a script to detect multiple window usage and notify the user can come handy. Let's see, how to do that.

Details...

Tags: web php javascript window name