Star79
asked on
document.addEventListener doesnt fire in IE 9 or any other IE versions
Hello,
I have a situation here, we want to copy the contents of grid (written in MVC) to clipboard and then copy it to Excel (using CTRL-V). So when I click on COPYGRID button on UI the following function copyGrid() is called but the eventlistener (document.addEventListener ) doesn't get fired. Your help is highly appreciated as this issue is kind of urgent.
Here is the code
-----------------------
document.addEventListener( 'copy', function (e) {
console.log(e);
try{
alert("starting to copy to clipboard");
e.clipboardData.setData('t ext/html', searchString);
e.preventDefault();
alert("Table copied to clipboard");
} catch (e) {
alert("Issue copying table to clipboard");
}
});
function copyGrid() {
document.execCommand('copy ', false, copyGrid);
}
Regards,
Rithesh
I have a situation here, we want to copy the contents of grid (written in MVC) to clipboard and then copy it to Excel (using CTRL-V). So when I click on COPYGRID button on UI the following function copyGrid() is called but the eventlistener (document.addEventListener
Here is the code
-----------------------
document.addEventListener(
console.log(e);
try{
alert("starting to copy to clipboard");
e.clipboardData.setData('t
e.preventDefault();
alert("Table copied to clipboard");
} catch (e) {
alert("Issue copying table to clipboard");
}
});
function copyGrid() {
document.execCommand('copy
}
Regards,
Rithesh
Maybe this will help.
common practice is to check if the addEventListener method is available and use it, otherwise use attachEvent:
function bindEvent(el, eventName, eventHandler) {
if (el.addEventListener){
el.addEventListener(eventName, eventHandler, false);
} else if (el.attachEvent){
el.attachEvent('on'+eventName, eventHandler);
}
}
// ...
bindEvent(document.getElementById('myElement'), 'click', function () {
alert('element clicked');
});
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER