Jump to content
Larry Ullman's Book Forums

How To Create My Own Javascript Sdk For Advertising


Recommended Posts

I need to make an advertising software development kit for users to integrate into their own website. I have a generous PHP & MySQL knowledge, but not so much for Javascript. I would like it to:

 

(a) Connect to the Database

(B) Select an Ad at random

© Not reveal anything about a PHP script

(d) Return as a frame

 

an example of what I need is like Google's AdSense program. If you look at an ad, it is in a frame. I need something like this.

Link to comment
Share on other sites

If you don't mind me asking, why do you need JS at all for your solution? When the page loads, couldn't you simply use PHP to randomly select an ad from the DB, and then load that into an iframe (which is what Google's AdSense does)?

 

I'm not actually sure how Google's AdSense works behind the scenes though. If the ads are loaded into an iframe, then that would seem to suggest that the ads are seperate URLs that can be linked to, which may or may not be the situation in your case. Either way, iframes make sense in that they allow for the parallel loading of the ad content with the page content.

 

Anyway, if you need JS for some reason, you're going to want to look into Ajax. Also, if you're not confident in your JS skills, I'd start reading Larry's book first, and then come back here if/when you get stuck.

  • Upvote 1
Link to comment
Share on other sites

What I am looking for is also similar to the Facebook integration. It calls a javascript file and in the DIV tag it will have information on what to call specifically:

 

<div id="fb-like" data-width="450" data-height="100" data-href="myhome.com"></div>

 

This will tell the javascript to call the FB LIke item, style it to 450px wide and 100px high, and any action (liking the page) will insert info into the database for 1 like by a certain person, for a certain page.

 

I need to do this with a hosting company I work for. To have ads program, and an API for clocks, and other useful widgets. I need to have the ability to have users style it, and use it on their site to their custom style. If you need more info, just ask.

Link to comment
Share on other sites

My recommendation would be to start by looking at the Google AdSense (public) code to see how they do it. I believe AdSense uses a bit of HTML and JavaScript to create an iframe in the page. The source of the iframe can be the PHP script that connects to the database. Should be relatively straightforward.

Link to comment
Share on other sites

I don't really have a lot of JavaScript knowledge. And the AdSense code is REALLY complex. I just need it to create an IFRAME based on what is placed in the DIV tag.

 

<div id="ihost-widget" widget-type="clock" widget-width="125" widget-height="125" user-id="12491463"></div>

 

will create an IFRAME that access the URL:

 

api.myhostdomain.im/widget.php?type=clock&width=125&height=125&uid=12491463

 

I can create the widget PHP script. I just need the JavaScript.

 

And I cannot purchase Larry's book right now. I need to get this job done before I can get paid.

Link to comment
Share on other sites

I'm not too familiar with dealing with undefined HTML element attributes like widget-type, etc. Basically, I don't think it's valid markup (well, maybe in XHTML). Anyway, the following sample script will give you what you want:

 

<!DOCTYPE html>

 

<html lang="en">

 

<head>

 

<meta charset="UTF-8">

 

<title>Google AdSense JS sample</title>

 

</head>

 

<body>

 

<div id="ihost-widget" widget-type="clock" widget-width="125" widget-height="125" user-id="12491463"></div>

 

<script>

 

var ihost_widgetDiv = document.getElementById('ihost-widget'),

widget_typeAtrb = ihost_widgetDiv.getAttribute('widget-type'),

widget_widthAtrb = ihost_widgetDiv.getAttribute('widget-width'),

widget_heightAtrb = ihost_widgetDiv.getAttribute('widget-height'),

user_idAtrb = ihost_widgetDiv.getAttribute('user-id');

 

document.body.innerHTML = 'widget-type: ' + widget_typeAtrb + '<br>';

document.body.innerHTML += 'widget-width: ' + widget_widthAtrb + '<br>';

document.body.innerHTML += 'widget-height: ' + widget_heightAtrb + '<br>';

document.body.innerHTML += 'user-id: ' + user_idAtrb;

 

</script>

 

</body>

 

</html>

  • Upvote 1
Link to comment
Share on other sites

I meant to put this in my other post, but anyway, after that, you will have to use Ajax to actually feed that info to a PHP script. Sorry, but I'm not going to just give you that code too. If you look at Larry's book or go online and search for how to use Ajax, you can probably figure it out though.

  • Upvote 2
Link to comment
Share on other sites

Thanks so very much. I got a code from elsewhere on how to create an IFRAME from javascript. So I put both codes together to make an IFRAME connected to the DIV attributes. This will help the company I work for, and our progress on creating the website,

 

Thanks again. Thanks to Larry for being an awesome author (I read his PHP & MySQL Visual Quick Pro Second Edition book)

Link to comment
Share on other sites

 Share

×
×
  • Create New...