1

In my application (using Zend Framework), I have a layout file (layout.phtml) with the <head> section including some javascripts this way:

<head>
  // Some code
  <?php include('template/javascript.php') ?>
</head>

And in the javascript.php I have:

<?php
  print '<script type="text/javascript; 
    src="'.PASTA_JAVASCRIPT.DS_URL.'jquery'.DS_URL.'jquery.js" ></script>';
  print '<script type="text/javascript; 
    src="'.PASTA_JAVASCRIPT.DS_URL.'application.js" ></script>';
  // More code

The thing is, when I use Firefox, all of these scripts are loading correctly and its ready to use. But when using Google Chrome, besides they are being rendered on the html header, I can't use jquery or any other variables I defined on my application.js.

One other point I need to mention is that if I remove the php include code and manually set the scripts inside the <head> tag like the code below, it works like a charm:

<head>
  <script type="text/javascript" 
    src="/path/to/my/scripts/jquery.js"></script>
</head>

All I could think of is some crazy behavior of Php's print/echo or Google Chrome's way of interpreting things... Seriously, I have no idea.
Anyone know what could be possibly causing this behavior?

3
  • 1
    Semicolon at the end of the text/JavaScript might b causing this issue. Commented Jan 15, 2013 at 17:54
  • 2
    Seems like you miss a quote. Also no semicolon allowed in the type attribute. should be print '<script type="text/javascript" src="'.PASTA_JAVASCRIPT.DS_URL.'application.js" ></script>'; Commented Jan 15, 2013 at 17:57
  • @insomiac was right. Weird that it works on firefox. Anyway, if you put your comment as an answer i will accept it. Commented Jan 15, 2013 at 17:58

1 Answer 1

2

Seems like semicolon issue..

javascript.php - Try this

<?php
      print '<script type="text/javascript" src="'.PASTA_JAVASCRIPT.DS_URL.'jquery'.DS_URL.'jquery.js" ></script>';
      print '<script type="text/javascript" 
        src="'.PASTA_JAVASCRIPT.DS_URL.'application.js" ></script>';

Or use echo

<?php
    echo '<script type="text/javascript" src="'.PASTA_JAVASCRIPT.DS_URL.'jquery'.DS_URL.'jquery.js" ></script>';
    echo '<script type="text/javascript" 
            src="'.PASTA_JAVASCRIPT.DS_URL.'application.js" ></script>';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.