Good afternoon. I have an application where I am tying a function to a button. When the button is pressed, I want the window/application to close. For some reason, I am getting the message that exitApplication is not defined. Here is my simple code:
JavaScript
// Exit Application if User does not Acknowledge
function exitApplication() {
window.close();
}
HTML Portion
<div dojotype="dijit.form.Button" id="buttonExit" data-dojo-type="dijit/form/Button" type="button" style="align-content: center" onclick="exitApplication();">Close</div>
I have this working in another application (JavaScript 3.9 API). I am now trying to get this to work using the JavaScript 3.13 API.
Anyone have any ideas?
Thanks.
Solved! Go to Solution.
Is that function defined outside the "require" section of the code?
require([...], function(...){ //more code }); function exitApplication() { window.close(); }
That's usually the issue when this error pops up. Steve Cole's answer would probably have the same issue, since that would also be within the require. An alternative would be
registry.byId('buttonExit').on('click', function() { window.close(); });
I think your best bet is to add an event listener for the click event of your button:
on(dom.byId('buttonExit'), 'click', function() { exitApplication(); });
Since you're using a Dojo button, you could also do the same thing using dijit.byId as well:
on(dijit.byId('buttonExit'), 'click', function() { exitApplication(); });
Is that function defined outside the "require" section of the code?
require([...], function(...){ //more code }); function exitApplication() { window.close(); }
That's usually the issue when this error pops up. Steve Cole's answer would probably have the same issue, since that would also be within the require. An alternative would be
registry.byId('buttonExit').on('click', function() { window.close(); });
This line of code is it:
registry.byId('buttonExit').on('click', function() {
window.close();
openedWindow.close();
});
Thank you for all of your responses.
The window.close() works for I.E. what works for closing Google Chrome and FireFox Browsers?
It's not directly (officially) supported in Chrome or Firefox. You can read about some hackarounds here.
My answer was partially incorrect. If the function is inside the require statement, like shown below, then the html code will not be able to access it
require([...], function(...){ //more code function exitApplication() { window.close(); } }); <div dojotype="dijit.form.Button" id="buttonExit" data-dojo-type="dijit/form/Button" type="button" style="align-content: center" onclick="exitApplication();">Close</div>
When it is outside the require statement, like shown below, the event handling code won't be able to access it
require([...], function(...){ //more code registry.byId('buttonExit').on('click', exitApplication); }); function exitApplication() { window.close(); }