tags:

views:

54

answers:

2

I have a javascript function defined somewhere in the middle of my html/php based page like this -

<script language="javascript" type="text/javascript">
function popitup2() 
{
    newwindow2=window.open('','name','height=265,width=350');
    var tmp = newwindow2.document;
tmp.write('<html><head><title>Coupon</title>');
tmp.write('<link rel="stylesheet" href="<?php echo get_bloginfo('wpurl'); ?>/wp-content/themes/street/coupon.css">');
tmp.write('<script src="/street/coupon.js"> </script>');
tmp.write('<script src="http://code.jquery.com/jquery-1.4.2.min.js"&lt;/script&gt;');

... /*some other code which is working fine */

Now this web page appears broken when i open it. But if i remove the the following 2 lines from javascript the error goes and page appears fine.

tmp.write('<script src="/street/coupon.js"></script>');
tmp.write('<script src="http://code.jquery.com/jquery-1.4.2.min.js"&gt;&lt;/script&gt;');

Can someone tell what is wrong with coding of these lines.

+4  A: 

The browser is interpreting the </script> in the string as the end of the <script> tag.

Change it to

tmp.write('<' + 'script src="/street/coupon.js"></' + 'script>');
SLaks
+1  A: 

In your last line you have

tmp.write('<script src="http://code.jquery.com/jquery-1.4.2.min.js"&lt;/script&gt;');

which is missing the closing right-angle bracket. It should read:

tmp.write('<script src="http://code.jquery.com/jquery-1.4.2.min.js"&gt;&lt;/script&gt;');

Now, when you give the line again to show what you removed, it's rendered correctly, so I'm not sure if this is really the problem or you just made a typo the first time. Worth a try.

Robusto