1

In a html file , inside the body tag I've these lines of code

<script type="text/javascript" src="http://xxx.com/js/publisher/promo.js"></script>

and in the promo.js file, I've put these lines

<script type="text/javascript" src="/js/jquery-1.3.2.min.js?v=5-5-09"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript" src="/js/lazyload.js"></script>

and I get a javascript error(missing ; before statement) on the second line of promo.js file when I load the html file in the browser. Any ideas on why this is happening ?

3
  • 2
    There's a missing semicolon on line 1 or 2 in promo.js :D (also, better not put html in a js file) Commented Dec 27, 2011 at 21:02
  • Unless I'm misreading, you can't have HTML code in a JavaScript file - i.e. promo.js. Commented Dec 27, 2011 at 21:04
  • That is not how it works. You have to get the scripts tag inside your html file Commented Dec 27, 2011 at 21:04

3 Answers 3

2

JavaScript files do not recognize HTML text.

In your promo.js file, if you have that text in it, that is not valid javascript.

If you want to include additional scripts from your javascript file, you will need to dynamically add javascript file references.

Sign up to request clarification or add additional context in comments.

Comments

2

You cannot include scripts in the manner you're attempting to. You will either need to use a server-side script to dynamically create this bundle, or just put those three script includes right into your page.

Secondly, stop including two copies of jQuery; you only need one. You might want to update it as well, we're on 1.7.1 now.

Finally, <script> includes should go in the <head>, not the <body>.

1 Comment

That's not quite right. Including scripts at the bottom of your document body can make page load times appear quicker. There's nothing technically wrong with it. And although he's done a rather botched job there's something to be said for having a fallback for a CDN jQuery (although admittedly this isn't working that way.)
2

The problem is that you put HTML-tags in a file that you have specificed to contain JavaScript, with your type="text/javascript" attribute.

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.