Firefox 3 Broke My Code

Yesterday, I had to install Firefox 3, because my most recent work stopped functioning properly in the new Firefox. I wanted to wait a little longer for Firefox 3 to be more stable, but had no other choice. Who would have thought the new version of my beloved Firefox would break my code? Basically, it [...]

Flash and Javascript

A useful function to interact with Flash movie with Javascript. Works in most browsers. Thanks Permadi.com!
function getFlashMovieObject(movieName)
{
if (window.document[movieName])
{
return window.document[movieName];
}
if (navigator.appName.indexOf(”Microsoft Internet”)==-1)
{
if (document.embeds && document.embeds[movieName])
return document.embeds[movieName];
}
[...]

Cross-Browser getElementById()

A useful Javascript function to return the ID of an element that is supposed to work on most browsers.Thanks Netlobo.com!
function returnObjById( id )
{
if (document.getElementById)
var returnVar = document.getElementById(id);
else if (document.all)
var returnVar [...]

Display and Hide DIVs Using Javascript and CSS

Suppose I have some text within <div id=”div1″></div> tags, it’s easy to display and hide this block of text with the help of some Javascript code and CSS.
To hide the block of text, do the following:
<script language=”javascript”>
document.getElementById(’div1′).style.display = ‘none’;
</script>
To display the block of text, just remove the word ‘none’ from the code above as follows:
<script [...]

Javascript to disable user from using the browser’s Back button

The following Javascript code would disable the user from using the browser’s Back button.
<script language=”javascript”>
window.history.forward(1);
</script>

Javascript Keywords

break case continue delete do else false [...]

Javascript window.innerWidth vs. document.body.offsetWidth

var winW = parseInt(”630″), winH = parseInt(”460″);
if (parseInt(navigator.appVersion)>3) {
if (navigator.appName==”Netscape”) {
winW = window.innerWidth;
winH = window.innerHeight;
}
if (navigator.appName.indexOf(”Microsoft”)!=-1) {
winW = document.body.offsetWidth;
winH = document.body.offsetHeight;
}
}
The above code returns the width and height of the browser window regardless if it’s Netscape or IE. If the browser is Netscape, we use innerWidth and innerHeight properties of the window object to return [...]

Javascript document.onmouseover

document.onmouseover=GetCoordinates;
function GetCoordinates(e){
if (navigator.appName==”Netscape”) {
xVal = parseInt(e.pageX);
yVal = parseInt(e.pageY);
}
if (navigator.appName.indexOf(”Microsoft”)!=-1) {
xVal=parseInt(event.x);
yVal=parseInt(event.y);
}
}
This line of code document.onmouseover=GetCoordinates; causes the onmouseover to be fired and calls function GetCoordinates, which is used to keep track of every single mouse movement. Also, the appName property of the javascript navigator object is used to identify the user’s browser. If the browser is [...]

Javascript document.onclick

document.onclick=WindowClickEventExplorer;
function WindowClickEventExplorer(e){
if (navigator.appName==”Netscape”) {
popIt=0;
}
if (navigator.appName.indexOf(”Microsoft”)!=-1) {
var WinEvent = window.event.srcElement.tagName;
if (WinEvent ==’INPUT’ || WinEvent ==’IMG’ || WinEvent ==’A’ || WinEvent ==’B’ || WinEvent ==’SELECT’) popIt=0;
}
}
The above code captures all the click events within the document inside the current browser and calls function WindowClickEventExplorer at the mouse click. Inside function WindowClickEventExplorer, appName property of javascript navigator object [...]

Javascript Location Object

The Javascript location object has 3 important properties: href, host, and protocol and 2 methods: replace() and reload()
location.href - returns the current URL
location.host - returns the current Host
location.protocol - returns the protocol used
window.location.href = “http://www.newurl.com” - sends user to “http://www.newurl.com”
window.location.replace(”http://www.newurl.com”) - sends user to “http://www.newurl.com”
setTimeout(”location.reload()”,100000) - refreshes the current page every 100 seconds