最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

html - JavaScript: Uncaught ReferenceError: confirm_Logout is not defined (anonymous function) - Stack Overflow

matteradmin6PV0评论

So I'm pretty new to javascript...right now I'm just writing that dynamic logout button that will go log the user out before reloading the page. I wrote the function (this is actually my entire script.js file):

var scriptLoaded = true;
function confirm_logout()
{
   var logout = GetURL('logout_confirm.php');
   if(logout == 'true')
   {
      location.reload(true);
      return true;
   }
   else
   {
      return false;
   }
}

And then I'm loading it up with this:

<script type="text/javascript" src="script/script.js">
   var scriptLoaded = false;
</script>

So what I'd like is just put it inside an anchor tag, but for the sake of testing (it wasn't working, and I just wanted to slim it down) I did this:

<script type="text/javascript">
   var LoggedOut = false;
   if(scriptLoaded == true)
   {
       LoggedOut = confirm_Logout();
   }
   document.write(LoggedOut);
</script>

Then I run it in chrome and in the debugging console I get the error: Uncaught ReferenceError: confirm_Logout is not defined (anonymous function).

Help me stack overflow, you're my only hope.

So I'm pretty new to javascript...right now I'm just writing that dynamic logout button that will go log the user out before reloading the page. I wrote the function (this is actually my entire script.js file):

var scriptLoaded = true;
function confirm_logout()
{
   var logout = GetURL('logout_confirm.php');
   if(logout == 'true')
   {
      location.reload(true);
      return true;
   }
   else
   {
      return false;
   }
}

And then I'm loading it up with this:

<script type="text/javascript" src="script/script.js">
   var scriptLoaded = false;
</script>

So what I'd like is just put it inside an anchor tag, but for the sake of testing (it wasn't working, and I just wanted to slim it down) I did this:

<script type="text/javascript">
   var LoggedOut = false;
   if(scriptLoaded == true)
   {
       LoggedOut = confirm_Logout();
   }
   document.write(LoggedOut);
</script>

Then I run it in chrome and in the debugging console I get the error: Uncaught ReferenceError: confirm_Logout is not defined (anonymous function).

Help me stack overflow, you're my only hope.

Share Improve this question asked Dec 7, 2010 at 16:30 CrowderSoupCrowderSoup 1645 silver badges16 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

You need to write confirm_logout, not confirm_Logout (lowercase 'l').

<script type="text/javascript">
   var LoggedOut = false;
   if(scriptLoaded == true)
   {
       LoggedOut = confirm_logout();
   }
   document.write(LoggedOut);
</script>

You can't execute Javascript in a script element if it has a src it's referencing. Also, you defined confirm_logout and you are calling confirm_Logout, capital L which is why you get confirm_Logout is not defined.

Post a comment

comment list (0)

  1. No comments so far