I am working on creating a
synthetic event in Safari (this fails in both 1.2.X and 2.0 beta). I am
attempting to call the onclick event handler on an image with an id of
"image1". The following code successfully dispatches the event on Firefox and
Mozilla, but fails on Safari. The expected behavior is for the alert to be
displayed when the page loads, or anytime the image is
clicked.
Am I doing something wrong, or is
this mechanism broken?
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Test Safari
dispatchEvent method</title>
<script
language=_javascript_>
function getObj(name) //
cross browser capable object reference retriever
{
if (document.getElementById)
{
this.obj =
document.getElementById(name);
this.style = document.getElementById(name).style;
}
else if (document.all)
{
this.obj = document.all[name];
this.style = document.all[name].style;
}
else if (document.layers)
{
this.obj = getObjNN4(document,name); // this function is not included as it is
irrelevant
this.style = this.obj;
}
}
function
clicked()
{
alert("Image Clicked.");
}
window.
()
{
var clickImage = new getObj("image1");
var >
onClickEvent.initEvent("click", true, true);
clickImage.obj.dispatchEvent(onClickEvent);
};
</script>
</head>
<body>
<img id=image1
src="" >
</body>
</html>
Andrew
Lippert
Vice President of
Engineering
Apex
Learning
315 5th Ave.
South, Suite 600
Seattle, WA
98104