Search code examples
javascriptinternet-exploreronbeforeunload

setting onbeforeunload on IE11


I'd like confirmation, should I be able to set onebeforeunload on an opened window in IE11.

Edit: some extra info

The page opening the window is located on a page such as

https://subsub.sub.company.tld/someapp/#/somepage

The window is opening an url like

https://subsub.sub.company.tld/someService/SomeIdentifier?timestamp=214124

As far as I am aware this should be fine?

var pop = window.open("url-on-same-domain");
pop.addEventListener("beforeunload", function() {
   //something here
}):

Currently I can't add this listener due to Permissions (as far as I know this shouldn't be an issue on a same-domain environment). It does however have a unverified SSL connection e.g. defect certificate due to dev env.

Error: Permission denied ... some stack which goes back to pop.addEventListener

I also tried setting pop.onbeforeunload = function(){} but this is being ignored.

Anyone who can fill me in on this? We also have an issue on our test environment which is on localhost where attaching the evenListener won't work on IE and Edge.


Solution

  • My problem was caused by the popup opening a PDF File. In IE there is never access to Files opened in a window.

    We worked around this by wrapping the file in an iFrame, which might sound nasty, but we needed to be able to display custom messages sometimes so it was OK for us as no other solution was workable.