最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论