Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2012
    Posts
    5
    Plugin Contributions
    0

    Default page specific javascript

    looking at http://www.zen-cart.com/showthread.p...ader-php-pages

    i want to add a certain javascript to specific pages by product ids
    using the threads example:

    if ($current_page_base == 'product_info' && $_GET['products_id'] == '32') {
    // do code here
    }


    so i have added to my templates html_header.php page

    if ($current_page_base == 'product_info' && $_GET['products_id'] == '32') {
    <script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script>

    <script language="JavaScript">

    var country= geoip_country_code();

    if(country == "US" || country == "CA")

    {
    <!--
    window.location = "http://www.test.com/USA.html"
    //-->
    }
    else
    {
    <!--

    //-->
    }
    </script>
    }

    i can get it to work if i add a php statement but not for a javascript one, i get a 500 error, i know i must have the syntax wrong but i dont know enough about it
    can someone please help :)

  2. #2
    Join Date
    Aug 2005
    Location
    Arizona
    Posts
    27,755
    Plugin Contributions
    9

    Default Re: page specific javascript

    Post complete code so we can see where you might have made a mistake

    Try using the code tags
    Zen-Venom Get Bitten

  3. #3
    Join Date
    Dec 2012
    Posts
    5
    Plugin Contributions
    0

    Default Re: page specific javascript

    its the standard html_header.php file that comes with the ashley pink template
    i have just added in the above code to where Drbyte said to in the other thread
    under - require(DIR_WS_MODULES . zen_get_module_directory('meta_tags.php'));

    Code:
    <?php
    /**
     * Common Template
     *
     * outputs the html header. i,e, everything that comes before the \</head\> tag <br />
     *
     * @package templateSystem
     * @copyright Copyright 2003-2010 Zen Cart Development Team
     * @copyright Portions Copyright 2003 osCommerce
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     * @version $Id: html_header.php 15761 2010-03-31 19:31:27Z drbyte $
     */
    /**
     * load the module for generating page meta-tags
     */
    require(DIR_WS_MODULES . zen_get_module_directory('meta_tags.php'));
    if ($current_page_base == 'product_info' && $_GET['products_id'] == '32') {
    <script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script>
    
    <script language="JavaScript">
    
    var country= geoip_country_code();
    
    if(country == "US" || country == "CA") 
    
    {
    <!--
    window.location = "http://www.test.com/USA.html"
    //-->
    }
    else 
    {
    <!--
    
    //-->
    }
    </script>
    }
    /**
     * output main page HEAD tag and related headers/meta-tags, etc
     */
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" <?php echo HTML_PARAMS; ?>>
    <head>
    <title><?php echo META_TAG_TITLE; ?></title>
    <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>" />
    <meta name="keywords" content="<?php echo META_TAG_KEYWORDS; ?>" />
    <meta name="description" content="<?php echo META_TAG_DESCRIPTION; ?>" />
    <meta http-equiv="imagetoolbar" content="no" />
    <meta name="author" content="The Zen Cart&trade; Team and others" />
    <meta name="generator" content="shopping cart program by Zen Cart&trade;, http://www.zen-cart.com eCommerce" />
    <?php if (defined('ROBOTS_PAGES_TO_SKIP') && in_array($current_page_base,explode(",",constant('ROBOTS_PAGES_TO_SKIP'))) || $current_page_base=='down_for_maintenance' || $robotsNoIndex === true) { ?>
    <meta name="robots" content="noindex, nofollow" />
    <?php } ?>
    <?php if (defined('FAVICON')) { ?>
    <link rel="icon" href="<?php echo FAVICON; ?>" type="image/x-icon" />
    <link rel="shortcut icon" href="<?php echo FAVICON; ?>" type="image/x-icon" />
    <?php } //endif FAVICON ?>
    
    <base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER . DIR_WS_HTTPS_CATALOG : HTTP_SERVER . DIR_WS_CATALOG ); ?>" />
    <?php if (isset($canonicalLink) && $canonicalLink != '') { ?>
    <link rel="canonical" href="<?php echo $canonicalLink; ?>" />
    <?php } ?>
    
    <?php
    /**
     * load all template-specific stylesheets, named like "style*.css", alphabetically
     */
      $directory_array = $template->get_template_part($template->get_template_dir('.css',DIR_WS_TEMPLATE, $current_page_base,'css'), '/^style/', '.css');
      while(list ($key, $value) = each($directory_array)) {
        echo '<link rel="stylesheet" type="text/css" href="' . $template->get_template_dir('.css',DIR_WS_TEMPLATE, $current_page_base,'css') . '/' . $value . '" />'."\n";
      }
    /**
     * load stylesheets on a per-page/per-language/per-product/per-manufacturer/per-category basis. Concept by Juxi Zoza.
     */
      $manufacturers_id = (isset($_GET['manufacturers_id'])) ? $_GET['manufacturers_id'] : '';
      $tmp_products_id = (isset($_GET['products_id'])) ? (int)$_GET['products_id'] : '';
      $tmp_pagename = ($this_is_home_page) ? 'index_home' : $current_page_base;
      if ($current_page_base == 'page' && isset($ezpage_id)) $tmp_pagename = $current_page_base . (int)$ezpage_id;
      $sheets_array = array('/' . $_SESSION['language'] . '_stylesheet',
                            '/' . $tmp_pagename,
                            '/' . $_SESSION['language'] . '_' . $tmp_pagename,
                            '/c_' . $cPath,
                            '/' . $_SESSION['language'] . '_c_' . $cPath,
                            '/m_' . $manufacturers_id,
                            '/' . $_SESSION['language'] . '_m_' . (int)$manufacturers_id,
                            '/p_' . $tmp_products_id,
                            '/' . $_SESSION['language'] . '_p_' . $tmp_products_id
                            );
      while(list ($key, $value) = each($sheets_array)) {
        //echo "<!--looking for: $value-->\n";
        $perpagefile = $template->get_template_dir('.css', DIR_WS_TEMPLATE, $current_page_base, 'css') . $value . '.css';
        if (file_exists($perpagefile)) echo '<link rel="stylesheet" type="text/css" href="' . $perpagefile .'" />'."\n";
      }
    
    /**
     * load printer-friendly stylesheets -- named like "print*.css", alphabetically
     */
      $directory_array = $template->get_template_part($template->get_template_dir('.css',DIR_WS_TEMPLATE, $current_page_base,'css'), '/^print/', '.css');
      sort($directory_array);
      while(list ($key, $value) = each($directory_array)) {
        echo '<link rel="stylesheet" type="text/css" media="print" href="' . $template->get_template_dir('.css',DIR_WS_TEMPLATE, $current_page_base,'css') . '/' . $value . '" />'."\n";
      }
    
    /**
     * load all site-wide jscript_*.js files from includes/templates/YOURTEMPLATE/jscript, alphabetically
     */
      $directory_array = $template->get_template_part($template->get_template_dir('.js',DIR_WS_TEMPLATE, $current_page_base,'jscript'), '/^jscript_/', '.js');
      while(list ($key, $value) = each($directory_array)) {
        echo '<script type="text/javascript" src="' .  $template->get_template_dir('.js',DIR_WS_TEMPLATE, $current_page_base,'jscript') . '/' . $value . '"></script>'."\n";
      }
    
    /**
     * load all page-specific jscript_*.js files from includes/modules/pages/PAGENAME, alphabetically
     */
      $directory_array = $template->get_template_part($page_directory, '/^jscript_/', '.js');
      while(list ($key, $value) = each($directory_array)) {
        echo '<script type="text/javascript" src="' . $page_directory . '/' . $value . '"></script>' . "\n";
      }
    
    /**
     * load all site-wide jscript_*.php files from includes/templates/YOURTEMPLATE/jscript, alphabetically
     */
      $directory_array = $template->get_template_part($template->get_template_dir('.php',DIR_WS_TEMPLATE, $current_page_base,'jscript'), '/^jscript_/', '.php');
      while(list ($key, $value) = each($directory_array)) {
    /**
     * include content from all site-wide jscript_*.php files from includes/templates/YOURTEMPLATE/jscript, alphabetically.
     * These .PHP files can be manipulated by PHP when they're called, and are copied in-full to the browser page
     */
        require($template->get_template_dir('.php',DIR_WS_TEMPLATE, $current_page_base,'jscript') . '/' . $value); echo "\n";
      }
    /**
     * include content from all page-specific jscript_*.php files from includes/modules/pages/PAGENAME, alphabetically.
     */
      $directory_array = $template->get_template_part($page_directory, '/^jscript_/');
      while(list ($key, $value) = each($directory_array)) {
    /**
     * include content from all page-specific jscript_*.php files from includes/modules/pages/PAGENAME, alphabetically.
     * These .PHP files can be manipulated by PHP when they're called, and are copied in-full to the browser page
     */
        require($page_directory . '/' . $value); echo "\n";
      }
    
    // DEBUG: echo '<!-- I SEE cat: ' . $current_category_id . ' || vs cpath: ' . $cPath . ' || page: ' . $current_page . ' || template: ' . $current_template . ' || main = ' . ($this_is_home_page ? 'YES' : 'NO') . ' -->';
    
    
    ?>
    <!--[if IE 6]><link rel="stylesheet" type="text/css" media="screen" href="includes/templates/ashley_pink/css/ie6.css" /><![endif]-->
    <!--[if IE 7]><link rel="stylesheet" type="text/css" media="screen" href="includes/templates/ashley_pink/css/ie7.css" /><![endif]-->
    </head>
    <?php // NOTE: Blank line following is intended: ?>

  4. #4
    Join Date
    Aug 2005
    Location
    Arizona
    Posts
    27,755
    Plugin Contributions
    9

    Default Re: page specific javascript

    The following is missing a closing tag
    Code:
    <script language="JavaScript">
    And this statement has been deprecated in favor of
    <script type="text/javascript">
    But this may not be all
    Zen-Venom Get Bitten

 

 

Similar Threads

  1. Specific sideboxe to show on specific page only
    By nicksab in forum General Questions
    Replies: 18
    Last Post: 17 Jul 2012, 07:22 AM
  2. How to call specific images with javascript?
    By GodfatherAntiques in forum General Questions
    Replies: 0
    Last Post: 18 Jan 2011, 08:25 PM
  3. specify javascript file for specific ez-page
    By orchidlake in forum Templates, Stylesheets, Page Layout
    Replies: 5
    Last Post: 28 Jan 2010, 12:47 AM
  4. Javascript in EZ-page
    By Mikado in forum General Questions
    Replies: 6
    Last Post: 14 Sep 2008, 08:54 AM
  5. CSS on specific pages, Javascript on all pages
    By banswidthjunkie in forum General Questions
    Replies: 6
    Last Post: 22 Dec 2007, 07:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg