Results 1 to 3 of 3

Thread: Defining JS variables in a "Global File"

  1. #1
    Join Date
    Dec 2011

    Defining JS variables in a "Global File"

    Hello all hope your having a good day.

    So I have written this JS for a custom site. I have created a "global" file in PHP that defines all the variables for the site and inputs them into all the pages that call for the those variables defined in "global". For example if you wanted to change the title of the site, you would go to the "global" PHP file and change the variable defined as title. This would change the title on every page of the site.

    Here's The Question

    Is there any way to define the JS variable $address (Red Below) in the "global" file I already have? (PHP file). Any solutions other than that? This way I do not have to go in and change every page by hand.

    Thank You in advance for your time.


    <code>/* Google Maps
    /* ---------------------------------------------------------------------- */

    // Needed variables
    var $map = $('#map'),
    $tabContactClass = ('tab-contact'),
    $address = '123 street roseville ca 95678';

    $content.bind('easytabs:after', function(evt,tab,panel) {
    if ( tab.hasClass($tabContactClass) ) {
    address: $address,
    zoom: 16,
    markers: [
    { 'address' : $address }

  2. #2
    Join Date
    Nov 2007
    As long as your global file writes the code to the browser, variables in the global file will function just fine.

    e.g., My site runs classic ASP and my JS file is actually a .asp file because I customize the JS based on a few things. So the reference to my JS file looks something like:
    <script src="/controls/javascript/main.asp?<&#37;=JSParams%>" type="text/javascript" ></script>
    My site also uses global files for stuff like global variable settings, navigation functions, etc.
    (e.g., "var ImagesDir", "Function Left-Nav", etc.). This file is included at the top of every page. If I update this page so that it writes javascript to the browser, this javascript is honored on every page.
        'blah blah - some ASP code here
      <script type="text/javascript">
          var someGlobalVariable = 'someValue';
      'some more ASP code here if I want it
    With the above, I can reference the javascript variable "someGlobalVariable" on any of my pages.

  3. #3
    Join Date
    Dec 2011
    Thank you very much. I just couldn't pin point my hand on the solution. This will help me a ton. Once again thanks.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center