[newbie] How to make simple JavaScript widget

Y

Yi

I want to make a simple javascript widget, something looks like the
Google AdWords, that people can just post a small section of code on
their web page and display some content from my website.

I searched online and found many javascript tools and packages but all
seem to be building widgets for a widget platform. I want something
that anybody can just copy and paste on their web page no matter they
are using ASP.NET or html or PHP for the pages.

ideas? pointers?

Thanks!
 
E

Evertjan.

Yi wrote on 10 jul 2008 in comp.lang.javascript:
I want to make a simple javascript widget, something looks like the
Google AdWords, that people can just post a small section of code on
their web page and display some content from my website.

You cannot "post" code on a website, you will have to insert it in the
sourcecode.
I searched online and found many javascript tools and packages but all
seem to be building widgets for a widget platform. I want something
that anybody can just copy and paste on their web page no matter they
are using ASP.NET or html or PHP for the pages.

HTML is clientside and quite capable of inserting an iframe,
no need for clientside javascript.

Serverside insertion would be much nicer, ASP, ASP.net and PHP run
serverside, ASP has serverside javascript, perhaps you mean that?

Better learn some javascript, Yi, it will come usefull not only to
programme, but also to understand wat you were asking here.
 
H

Hamish Campbell

Yi wrote on 10 jul 2008 in comp.lang.javascript:


You cannot "post" code on a website, you will have to insert it in the
sourcecode.


HTML is clientside and quite capable of inserting an iframe,
no need for clientside javascript.

Serverside insertion would be much nicer, ASP, ASP.net and PHP run
serverside, ASP has serverside javascript, perhaps you mean that?

Better learn some javascript, Yi, it will come usefull not only to
programme, but also to understand wat you were asking here.

A lot of platforms provide access to a templating engine, but not the
source itself.

Here is a complete, working solution in 3 lines:

Put this in the head of the page:

<script language="javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.2.6/jquery.min.js"></script>
<script language="javascript" type="text/javascript">$
(document).ready(function(){$.getScript("http://MyDomain/
MyScript.js")});</script>

This loads the jQuery library (jquery.com). Once the DOM is ready it
loads and executes a remote script located at http://MyDomain/MyScript.js.
Now you have all the jQuery functionality at your fingertips.

If we assume that the user has placed a div with the id "MyWidget", we
could do the following (for example):

[in MyScript.js]:
$('#MyWidget').html('Hey, check out this great new widget');

Personally, I think you'd be crazy to allow random code execution to
happen on your website, but that's up to your users.

Cheers,
Hamish
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top