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

  • SEARCH
  • Home
  • 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 6791227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:49:16+00:00 2026-05-26T17:49:16+00:00

I have my web applicatoin initialize method run based upon the page that is

  • 0

I have my web applicatoin initialize method run based upon the page that is loaded.

I need global variables available to only page 1 of 2. So what I want to do is define and initializ a global variable only if page 1 is loaded. I’m sure there is a way to do this but I do not know how to.

I pasted my releveant intitialze method and the two global I need. Currently they are defined and initialized on both page 1 reload and page 2 reload.

I want them only defined an intialized for page 1 reload.

/********************
group:globals
********************/

var local = 
  { 
  client_validation:1,
  persistent_element:'hide_1'
  };

window.onload=initialize_page;

/* 
- initialize_page() - function activated on each page load or reload.  Set by global window.onload
*/

function initialize_page()
  {
  var signin_found;
  /*Used to determine which page is loaded / reloaded*/
  if(signin_found=document.getElementById('signin_button')) 
    {
    signin_found.onclick=interface_signin;
    /*Interfaces and bindings*/
  • 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-26T17:49:16+00:00Added an answer on May 26, 2026 at 5:49 pm

    I think you’re probably overcomplicating this for yourself given that the variables in question are using negligable memory, but anyway the simplest way I can think of is to do this:

    function initialize_page() {
       if (/* somehow figure out if you're on page one */) {
          window.local = {
             client_validation:1,
             persistent_element:'hide_1'
          };
       }
    
       // etc.
    }
    

    Note that you can’t declare a variable conditionally by putting a var statement inside an if: JavaScript doesn’t have block scope (only function scope) so it will “hoist” the declaration up outside of the if. But in the case of global variables you can get around this because globals are essentially just properties of the window object so you can create the property conditionally as shown above.

    If you later realise that both pages have certain variables in common but also have their own separate requirements you can do this:

    var local = {
       commonSetting1 : "something",
       commonSetting2 : "something else"
    }
    
    function initialize_page() {
        if (/* page one? */) {
           // add page one's settings
           local["client_validation"] = 1;
           local["persistent_element"] = "hide_1";
        } else if (/* page two? */) {
           // add page two's settings
           local["somePageTwoSetting"] = "whatever";
           // etc.
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to devellop an internal web based application with codeigniter and I need
I have a web application that should behave differently for internal users than external
I have a web application written in C# that consumes several internal web services.
I have a web application developed with ASP.net and C# that is running on
I have a web application that is becoming rather large. I want to separate
I have a web application that needs to take a file upload from the
I have this web application that has grown to an unmanageable mess. I want
I have a web that was build using ASP.NET MVC 1.0. It uses Structuremap
I have created a timeclock application in C# that connects to a web service
I have A WCF service that has a class that inherits System.Web.Security.RoleProvider. In this

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.