On Jul 10, 11:19*pm, "Evertjan." <exjxw.hannivo...@interxnl.net>
wrote:
Quote:
Yi wrote on 10 jul 2008 in comp.lang.javascript
:
>
Quote:
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.
>
Quote:
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.
>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
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