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

So I'm pretty new to javascript...right now I'm just writing that dynamic logout button that

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745640344a4637652.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信