Home I don't know why JavaScript function for closing a tab errors out
Reply: 1

I don't know why JavaScript function for closing a tab errors out

M. Slomski
1#
M. Slomski Published in 2018-01-12 21:32:22Z

In my app I have this in the corresponding Angular controller:

     $scope.close_window = function() {
      window.close();
     };

The html template has this:

    <a href="javascript:close_window();">Quit</a>

The button fails to do anything and I see this error in the console:

Uncaught ReferenceError: close_window is not defined

I thought I defined as shown above. Is there something I am missing?

Ruchira Chamara
2#
Ruchira Chamara Reply to 2018-01-12 21:44:11Z

Yes you have used a function name without defining. Once you mentioned your function name like the following

        <a href="javascript:close_window();">Quit</a>

It is not going to look in to the angular scope object. You have defined your function in the scope object but haven't used it correctly. To use this create the command like the following.

        <a href="javascript:void();" ng-click="close_window()">Quit</a>
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.312113 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO