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 6173657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:36:50+00:00 2026-05-23T23:36:50+00:00

How can I define a global javascript variable in this situation? I want the

  • 0

How can I define a global javascript variable in this situation? I want the variable to be accessible from three places:

  1. the HTML page – I want to be able to reference the variable in the code in the HTML page favorites.php.
  2. the javascript file – In the HTML page I load a javascript file called portal.js with
  3. a PHP file – In the HTML file I load loadtreeb.php in an iframe. In loadtreeb.php I have echo javascript code and want to reference that variable in that code.

Here is a scenario.

In the HTML, favorites.php:

<head>
    <script type="text/javascript">
       var d = new dTree();
    </script>
</head>
<body>
        <iframe id="tnav" src="loadtreeb.php" style="border: 0px; width: 200px; height: 86%; overflow: auto;">
        </iframe>
</body

In the javascript file, portalb.js:

function deleteitem() {
     d.s(1);
     d.setCookie('csd', '1');
}

In the php file, loadtreeb.php:

echo '<script type="text/javascript">';

/* echo '   d = new dTree(\'d\');'; */

 echo "d.add('1','-1','My Favorites','#','','','images/root.gif','images/rootopen.gif','1');";

 echo  '    document.write(d);';

 echo 'd.s(0);';

 echo  '</script>';

In this scenario, I attempt to define the variable d in the header section of the HTML page, then I reference it in three places without redefining that variable. This doesn’t do it. The javascript statements echoed in the loadtreeb.php file don’t seem to know about the variable. They did when the variable was defined in the echo statements. But now I must access the same variable elsewhere. So I commented out the declaration statements and put it in the HTML script tag.

What is the way to achieve the accessiblity that I want in all of those places for that variable?

  • 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-23T23:36:51+00:00Added an answer on May 23, 2026 at 11:36 pm
    1. the HTML page – I want to be able to reference the variable in the code in the HTML page favorites.php.
    2. the javascript file – In the HTML page I load a javascript file called portal.js with

    Executing your javascript on the page is the same as having it directly in the page ( so it will access variable on the page on wich you execute it ( and that are before in the code ) ).

    The title is not quite correct, it would be exactly the same issue with only 2 html page ( and one in an iframe on the other ).

    So here if it’s on the same domain, you can just use :

    parent.window.d
    

    In the iframe to use the var in the parent frame.

    If you had wanted to use a var inside the iframe from the parent frame, you would have to do :

    window.frames["tnav"].d
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.