AJAX In Action [96]
var offset=8;
function showPopup(name,description){
var win=new ScriptIframePopup
(name,description,offset,offset,320,320);
offset+=32;
}
function ScriptIframePopup(name,description,x,y,w,h){
var bod=document.createElement("div");
document.body.appendChild(bod);
this.contentDiv=document.createElement("div");
this.contentDiv.className="winContents";
this.contentDiv.innerHTML=description;
bod.appendChild(this.contentDiv);
this.win=new windows.Window(bod,name,x,y,w,h);
}
Licensed to jonathan zheng 184 CHAPTER 5 The role of the server We define a function showPopup that takes a name and description as argument and constructs a window object for us. Listing 5.5 shows an example script that invokes this function. Listing 5.5 script_earth.js var name='earth'; var description="A small blue planet near the outer rim of the galaxy," +"third planet out from a middle-sized sun."; showPopup (name,description); We simply define the arguments and make a call against the API. Behind the scenes, though, we need to load this script from the server and persuade the browser to execute it. There are two quite different routes that we can take. Let’s examine each in turn. Loading scripts into IFrames If we load a JavaScript using an HTML document