There are several guides on how to disable onbeforeunload when the user clicks on the submit button. However, I can't find a guide that fits my case.
My Chrome Extension injects onbeforeunload Javascript into specific web pages. In those web pages, there are two buttons that both saves the form and leaves the page. Each button is tied to a function named opSubmit('T') and opSubmit('S')
What I want to do is, I want to disable onbeforeunload when those two functions are called (so that onbeforeunload doesn't throw confusing messege at users after they click save.). I can't get to know how to do this. I am attaching the elements code of those two buttons. Elements
I am also attaching my code:
background.js
chrome.tabs.onActivated.addListener( function(activeInfo){
chrome.tabs.get(activeInfo.tabId, function(tab){
y = tab.url;
if(y == "http://inje.u-folio.com/st/clinical-training/inpatient/pomr/create") {
chrome.tabs.executeScript({
file: '/js/inject.js'
});
};
};
});
inject.js
window.onbeforeunload = function(e) {
e.preventDefault();
return true;
};
Edit)
In short, I want to disable my 'inject.js's onbeforeunload event if a button on the webpage is clicked.
The button click calls a function called opSubmit(). I want to know whether if I can disable my 'inject.js's onbeforeunload event by overriding the page's opSubmit() function. I found this(Use a content script to access the page context variables and functions), but can't apply it to my case. Any help will be greatly appreciated.