This is, depending upon when it's called, OK for avoiding a conflict:
Code:
<script type="text/javascript">
function addEventHandler(obj, eventName,handler){
if (document.attachEvent){
obj.attachEvent("on" + eventName, handler);
} else if (document.addEventListener) {
obj.addEventListener(eventName, handler, false);
}
}
</script>
But it should be reversed and use the ever present window object, not the document object which might not be available for testing (again depending upon when it's used) yet in some browsers:
Code:
<script type="text/javascript">
function addEventHandler(obj, eventName, handler){
if (window.addEventListener){
obj.addEventListener(eventName, handler, false);
}
else if (window.attachEvent){
obj.attachEvent('on' + eventName, handler);
}
}
</script>
Once you have that, you no longer need:
Code:
window.onload = myonload;
Which does potentially expose itself to an onload conflict.
You can do instead:
Code:
<script type="text/javascript">
function addEventHandler(obj, eventName, handler){
if (window.addEventListener){
obj.addEventListener(eventName, handler, false);
}
else if (window.attachEvent){
obj.attachEvent('on' + eventName, handler);
}
}
</script>
<script type="text/javascript">
function myonload(){
addEventHandler(submit, "click" , function(){CngClass(obj)});
}
addEventHandler(window, 'load', myonload);
</script>
But this makes no sense unless submit is previously defined, which it's not in any of the code you are showing. And the obj argument in:
Code:
addEventHandler(submit, "click" , function(){CngClass(obj)});
can never be defined when called in that way.
If you want more help:
Please post a link to a page on
your site that contains the problematic code so we can check it out.
And since you seem to imply that each of these scripts work just fine on their own, post a link to two more pages:
- One where you have the thw.js working.
- Another where you have this CngClass code or whatever it is working.
Bookmarks