views:

410

answers:

3

Hello, I have been trying to figure out how I can generate a piece of javascript code that will allow site users to copy and paste it into their own sites, much like google Adsense and there embed code:

<– Begin Google Adsense code –>
<script type=”text/javascript”>
google_ad_client = “ad-client-code-goes-here”;
google_ad_slot = “ad-slot-code-goes-here”;
google_ad_width = 300;
google_ad_height = 250;
</script>
<script type=”text/javascript”
src=”http://pagead2.googlesyndication.com/pagead/show_ads.js”&gt;
</script>
<– End Google Adsense code –>

I would love to create something like that.I am doing a similar service as a project and would like users to upload an image (advertisement) and then have them click a link 'generate ad code' and then they will receive a similar piece of code snippet like the one above in which they can paste into their website.

Any help on this would be great, Thank you.

+1  A: 

I think I might be missing something... I'm assuming you're want to do this with Javascript? You would have your base code as a string in javascript (strScript in my example). Then you just replace the proper values, and throw it in a textbox?

var strScript = "<script>do_something_for_user(USER_ID);</script>" // Base script
strScript = strScript.replace(/USER_ID/, this_users_id)            // Replace the values
document.getElementById('someTextBox').value = strScript;            // Assign to textbox

That last line might be a tad off, but you'll be able to figure it out.

Matt Grande
+1  A: 

There are many ways to do this -

  • You can host the clickable ad image uploaded to the server in an IFrame. Basically you'll be giving the user the HTML code for an IFrame which will load the ad based on an advertisement id passed as a query string.

  • You can also use a simple image tag surrounded by an anchor tag acting as a link. The image will be loaded from a dynamic page based on the ad identifier.

Example 1

<iframe src="http://addomain.com/ad.aspx?id=123234234"&gt;&lt;/iframe&gt;

Example 2

<a href="http://addomain.com/adstracker.aspx?id=1223094"&gt;
    <img src="http://addomain.com/imageserver.aspx?id=1223094" />
</a>

The first example will load the iframe with a URL containing the ad id. The ad.aspx page will dynamically generate the ad based on the id passed to it in the query string.

The second example will redirect the user to an ad tracker page, which will track that the ad has been clicked, and then based on the ad id, the user will be redirected. The imageserver.aspx page will serve the ad image.

Kirtan
A: 

i am also looking for such solution, please any geeks!!!

eyoosuf