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.
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.

Hello TechTremor,

Not sure I understand your need but have a look to this artice :

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="">

This script would generate a button that could be clicked to send back URL destination to the host site (in this case 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="">

Open in new window

something like :

window.onload = function() {
	button = document.createElement("INPUT");
	button.type = "button";
	button.setAttribute("onclick", "document.location.href = ''");
	button.value = "Go to EE";
	document.getElementsByTagName("body")[0].appendChild( button );

Open in new window


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
Thanks for the points!
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

From novice to tech pro — start learning today.