Click to See Complete Forum and Search --> : function problems


xdef
03-17-2003, 11:06 AM
Ive been slaving over this for six hrs. Can someone please tell me why the img isnt loading into the new win.

I have to load four differnet img into the same window name...but i cant even get this one to work!

the code::

<html><head>
<title>Image in Popup Window</title>

<SCRIPT Language="JavaScript">

function displayPhoto(url,width,height,descrn) {

var url="";

var name="popup";
/*this var is called name which Thau says I shouldnt???*/
var w=width+50;
var h=height+120;

var features="width=" + w + ",height=" + h;

features+=",menubar=yes,scrollbars=yes,location=yes,status=yes,toolbars=yes";

var myNewWindow=window.open(url,name,features);

myNewWindow.focus();

myNewWindow.document.open();

myNewWindow.document.write("<html>");
myNewWindow.document.write("<head>");
myNewWindow.document.write("<title>image into new win</title>");
myNewWindow.document.write("<style type='text/css'>");
myNewWindow.document.write(" h1 {color:#003300;}");
myNewWindow.document.write(" body {background-color: red;}");

myNewWindow.document.write("</style>");
myNewWindow.document.write("</head>");
myNewWindow.document.write("<body>");
myNewWindow.document.write("<DIV ALIGN='CENTER'>")
myNewWindow.document.write("<h1>headline here</h1>");

myNewWindow.document.write("</DIV>");
myNewWindow.document.write("<form><br>");
myNewWindow.document.write("<input type='button' value='Close' onClick='parent.close()'><br>");
myNewWindow.document.write("</form>");
myNewWindow.document.write("</body>");
myNewWindow.document.write("</html>");
myNewWindow.document.close();

}

</SCRIPT>
</head>

<body>

<a href="JavaScript:displayPhoto('images/whatever.jpg',600,400,'a view from above')">A view from aboven</a>

</body></html>

gil davis
03-17-2003, 11:14 AM
var url="";Is this a typo? You pass the image to display in url, then you clobber it. Then, there is nothing anywhere in the rest of the code that writes out anything even remotely resembling an image tag. I think you should delete the file and start over. Think about what you want to do. Write it down in an logical orderly fashion. Then start writing code.

gil davis
03-17-2003, 11:17 AM
Perhaps you don't understand that document.write() on a completed (existing) document will erase what's there. It does not add on to the end, it starts over.

xdef
03-17-2003, 11:49 AM
Gil Davis was right in addressing the var url=""

I took that out and the script works fine.

So, what's this all about how it's all so wrong? Well, actually I also added an img
ref in the .write section. + width + height etc.

Sorry Gil but I think you misunderstood the code perhaps. I didn't write it,
Im just learning from it and it was written by my lecturer.

Now I can load as many img as I want into that same open popup.

*********************************
What do u do when u have a problem? Solve it.