M
Mark Anderson
Hi, I have this in an external JS library:
/////////////////////////
function addMyEvent(){
var obj;
if(document.attachEvent) {
obj = document.getElementsByTagName('img');
for (i=0;i<obj.length;i++) {
obj.attachEvent('ondrag', noDrag);
}
obj = document.getElementsByTagName('a');
for (i=0;i<obj.length;i++) {
obj.attachEvent('ondrag', noDrag);
}
}
}
function noDrag() {
// kill the drag event
return false;
}
////////////////////////
If I call it from the associated web page (no frames/IFrames, etc.
involved) via:
<body onload="addMyEvent();">
It works. If I try the unobtrusive metho and use <body> on the page
and...
window.onload = addMyEvent();
... in the JS library it fails. Have I got the syntax wrong or can only
the calling page use the 'onload' event.
[FWIW, I have to stop drags of images as their SRCs are query URLs and
dragged images get wrong names 'aspscript.jpg'. I provide a download
link for correct naming]
TIA,
Mark
/////////////////////////
function addMyEvent(){
var obj;
if(document.attachEvent) {
obj = document.getElementsByTagName('img');
for (i=0;i<obj.length;i++) {
obj.attachEvent('ondrag', noDrag);
}
obj = document.getElementsByTagName('a');
for (i=0;i<obj.length;i++) {
obj.attachEvent('ondrag', noDrag);
}
}
}
function noDrag() {
// kill the drag event
return false;
}
////////////////////////
If I call it from the associated web page (no frames/IFrames, etc.
involved) via:
<body onload="addMyEvent();">
It works. If I try the unobtrusive metho and use <body> on the page
and...
window.onload = addMyEvent();
... in the JS library it fails. Have I got the syntax wrong or can only
the calling page use the 'onload' event.
[FWIW, I have to stop drags of images as their SRCs are query URLs and
dragged images get wrong names 'aspscript.jpg'. I provide a download
link for correct naming]
TIA,
Mark