Best Practice for Javascript API Building

Looking at many services they are putting javascript files on your page which ends up generating the content in the form of forms, linkbacks, buttons, ads, ect.

To keep it simple lets say I wanted to create a button that users could click on any site and it would post back to a database on my main site and tell the DB what page they clicked. Kind of like dig.

I'm assuming most use JSON or similar to post the data back. However, how should the JS file be constructed that would generate the button on the site?

I haven't found any best practices or best ways to go about doing this.

Best Regards.
TechTremorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
Hello TechTremor,

Not sure I understand your need but have a look to this artice : http://wiki.apache.org/struts/AjaxStruts

Regards.
0
TechTremorAuthor Commented:
That explains a bit of the Ajax side, let me try to explain a bit better.

I would like to write some javascript that i could be included on any page on the web via:

<script language="javascript" src="site.com/jsfile.js">

This script would generate a button that could be clicked to send back URL destination to the host site (in this case site.com) server.

My question is whats the best practice to get the jsfile.js to generate a usable button on any site the js file is put on.



<script language="javascript" src="http://www.antonspaans.com/mysmugmug.js">

Open in new window

0
leakim971PluritechnicianCommented:
something like :


//mysmugmug.js
window.onload = function() {
	button = document.createElement("INPUT");
	button.type = "button";
	button.setAttribute("onclick", "document.location.href = 'http://www.experts-exchange.com'");
	button.value = "Go to EE";
	document.getElementsByTagName("body")[0].appendChild( button );
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
leakim971PluritechnicianCommented:
Thanks for the points!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.