I want to create a widget or a javascript code which will render a HTML form on the webpage where the code is embedded.
eg. www.example.com wants to show a BMI calculator which is hosted on www.example2.com example2 wants to share that BMI with example.com but is not giving the actual code. He will share just a js code ( Like how we include Google Analytics or Google Ads ). Whats the best way to achieve this?
In this calculator we are asking multiple details from the user which are saved in database on www.example2.com in db .
I don't want to go Java Applet or Flash way. Currently I have to share HTML code of the BMI calculator which is not ideal.
What are the possibilities here.
Thanks
There are two ways to do this: the iframe and javascript.
The more common way is to use the iframe, as it is a simple webpage on which you have full control. More, the best advantage is that the iframe is loaded asynchronously so the loading of the page isn't affected by the loading of the widget.
This is the approach that Facebook uses and as it does, also all other major sites use the same approach.
As pointed out in comments, using iframes permits you to use also the cookies, load css, javascript, ecc as it is a full webpage.
to use iframes you have to use a code like this:
<iframe id="WidgetContent" src="http://example.com/widget/id" frameborder="0" height="600"></iframe>
It's very simple!