How can i override the windows.onbeforeunload function only for an iframe?

291 Views Asked by At

I have an eventlistener

window.onbeforeunload=function(evt){
//causes pop up 
}

I need to override it with another event listener for an iframe(Download case here). The below code is not working

var tIFrame = document.getElementById('Download');

iFrame.contentWindow.addEventListener('beforeunload', wrappedFn, false);

iFrame.addEventListener('beforeunload', wrappedFn, true);

1

There are 1 best solutions below

0
On

Thanks @Bergi for the hint. The below code worked for me

var iFrame=document.getElementById('Download');
iFrame.contentWindow.onbeforeunload=function(){}
iFrame.contentWindow.location.href=sCmd;