Skip to main content
Hi - window.onbeforeunload function is not working for me in the salesforce lightning environment. I have a visualforce page styled using Lightning design system, we I view the page in classic the window.onbeforeunload works fine and pops out the standard not saved messagebox when I switch the tab. However, when I switch back to lightning and try the same(change the tab) then its not working.

window.onbeforeunload = function(e) {

  return 'changes not saves';

Anyone ever come across this scenario.? Please suggest on what I'm doing wrong here,
6 respuestas
  1. 1 ago 2017, 11:50
    As per my knowledge, window.onbeforeunload will not work because in lightning everything loads in a seperate iframe.

    In Lightning - So basically in Lightning when your visualforce is loaded the window is already prepared behind the scene

    In Classic - Whevener you are going to your specific tab the page is loaded i.e (whole Classic is loaded) that's why you can handlet the window events.

    Hope you understood.

    To achieve your functionality you need to use jQuery plugin and you need to write some events like .ready or other depending on your requirement.

    Let me know if you find this useful.
0/9000