Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4028030
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:10:12+00:00 2026-05-20T11:10:12+00:00

I have problems with calling a JavaScript function (which is inside of an object,

  • 0

I have problems with calling a JavaScript function (which is inside of an object, in it’s own .js file) from an other HTML page. In the code exsample I’ll just use a simple Hello World function.

    //.js file

    window.addEvent('domready',function(){

      var Site = {
        //Here I have like three other functions

        //This function I want to detect the browser version. I use MooTools for this
        detectBrowser : function(){
         if(Browser.ie){
          //Then what ever content goes here
         }
        } 
       }

       //I execute the other three functions here because they need to be called on every page
       Site.dropdownmenu();
       Site.accordion();
       Site.lightbox();
     });

I’m working with MooTools so I have wraped everything inside of the domready function.
Now, I want this cetect function to execute only at one page. I have tried somethink like this:

    //In the HTML file between two script tags:
    Site.alert(); 

That does’nt work. Any ideas?
If I execute it in the .js file it works fine. But I don’t want it to execute at every page.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:10:13+00:00Added an answer on May 20, 2026 at 11:10 am

    If you declare a variable with var in a function, the variable is local to that function and inaccessible from outside that function. To make it explicitly global, declare it as a property of window:

    window.addEvent('domready',function(){
        window.Site = ...
    

    This isn’t necessary for the code to work, it just makes it explicit for programmers that might read your code that Site is a global.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are there any inherent problems with calling an ole object from tsql? I have
I have an onclick function which performs several tasks. In another JavaScript function I
'Hi I am calling a web service from javascript/jquery as follows: function Test(userid) {
Follow on from: Javascript wait for image to load before calling Ajax function initResources()
I have a problem. I am coding using VS2008. I am calling webservices from
I frequently have problems dealing with DataRows returned from SqlDataAdapters . When I try
I seem to always have problems with converting data to and from XML in
I have an ASP.net repeater on my page which creates a load of listitems.
I have this JavaScript code: for (var idx in data) { var row =
I have a lengthy JavaScript file that passes JSLint except for used before it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.