views:

47

answers:

3

I'm trying to generate an Amazon ad that should look like this.

<script type="text/javascript"><!--
amazon_ad_tag = "xxxxxxx"; amazon_ad_width = "160"; amazon_ad_height = "600";//--></script>
<script type="text/javascript" src="http://www.assoc-amazon.com/s/ads.js"&gt;&lt;/script&gt;

Below are parts of my script that should achieve that. The script BTW is for rotating more types of affiliate ads.

First is a global variable with all the Amazon ad options...

ad_code = 'amazon_ad_tag = "xxxxxxx"; amazon_ad_width = "160"; amazon_ad_height = "600";';

Next I'm loading the ad_code in a "ad_slot" div. The contents of ad_code should appear between <script> tags.

$('.amazon_ad').html('<scr'+'ipt type=\"text/javascript\"><!--' + ad_code + '//--></scr'+'ipt><scr'+'ipt src=\"' + window.location.protocol +'//www.assoc-amazon.com/s/ads.js\" type=\"text/javascr'+'ipt\"></scr'+'ipt>');

The result should be the first code I posted and display an Amazon banner, instead my browser goes to http://www.assoc-amazon.com/s/ads.js, the script that should load.

Does anyone know what I'm doing wrong?

A: 

Is this wrapped in a $(document).ready(function(){ ... ? Works fine for me if it's inside that.

methodin
It was wrapped in `$(function() {` but I changed it and get the same result :( Did you change anything else?
V777
Nope a simple with with document.ready and your source worked great. What is the HTML of the class="amazon_ad" element?
methodin
A: 

Ensure the content/mime type for the .js files is set correctly in your server configuration. You can do this with .htaccess files.

Also you need to comment out or remove the <!-- comment in your script tag as that is not valid js

balupton
A: 

This is probably not the best time to criticize your code but:

All your script should be included externally, not inline. Do not use , this is a deprecated, ancient way of including inline script. If you must, use // I see in your script you are using document.write(). DON'T!

You cannot cheat and include a script in such a way and expect it to be executed.

Use jQuery.getScript()

tandu