I am creating a web widget that will be very easy to integrate. Let's say http://www.bicycleseller.com/
wants to integrate my widget into its web page. All he needs to do is copy and paste the following into the chapter section of his page:
<script src="http://www.widgetprovider.com/widget.js" type="text/javascript"></script> <script> Widget.create("123456accessKeyOfBicycleSeller").render("myWidget"); </script>
and <div id="myWidget"></div>
anywhere in the body. The widget will be displayed in this div.
I, as a widget provider, host widget.js :
var Widget = new function () { this.url = "www.widgetprovider.com/widget.jsp"; this.name = ""; this.parameters = "width=400,height=200,screenX=750,screenY=300,resizable=0"; this.create = function (accessKey) { this.accessKey = accessKey; return this; }; this.render = function (divId) { // make sure the document is fully loaded and place the widget on BicycleSellers page. // when the widget (a jpeg) is clicked, a jsp page I host will popup. window.onload = function () { document.getElementById(divId).innerHTML = '<img src="images/widget-image.jpg" onclick="Widget.display()"/>'; }; return this; }; this.display = function () { // open a popup window that displays a page I host. var popup = window.open(this.url + "?accessKey=" + this.accessKey, this.name, this.parameters); popup.focus(); return this; }; };
So, BicycleSeller places the widget on its page, and when its users click on it, a pop-up window appears that displays their contents on the page that I place. However, every webmaster who wants to embed my widget must provide an accessKey
that is unique to them, because the contents of the popup will depend on this.
My questions:
1) . In this case, anyone who goes to bicycleseller.com
and looks at the HTML source code can see its accessKey
, which is hardcoded in the section of the chapter. Then they can simply go to www.widgetprovider.com/widget.jsp?accessKey=123456
. I do not want this to happen. What can be done about this? For instance; I looked at the source of Facebook, and they seem to have hidden everything very well.
2) Is this a good way to create a widget? I was thinking about a lightbox, not a popup (which might be blocked by a popup blocker, although this is not the case in this example). Any comments / suggestions are welcome.
3) If I try to place in widgets and write Widget.create("key1").render("div1"); Widget.create("key2").render("div2");
Widget.create("key1").render("div1"); Widget.create("key2").render("div2");
, two images will be created. But when clicked, both pop-ups display key1
information. This is because the Widget
class in widget.js
is single. If I do not make it single, then I cannot put the image onclick
attribute ( Widget.display()
). What should I do for this?
Seek help on three issues. Any help would be appreciated. Thanks.