Forum Moderators: open
I had refered smokeyb to msg#4 in the Generic Javascript [webmasterworld.com] thread. He continues in the following post.
Note there are lots of other goodies in that thread as well
It's part of the Javascript Forum Library [webmasterworld.com].
<html>
<head>
<title>Catalogue</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script
type="text/javascript"
language="JavaScript">
<!--
function popUp(theURL,features) {
props=window.open(theURL, 'poppage', features);
props.document.write("<HTML><HEAD><TITLE>Painting View<\/TITLE><\/HEAD><BODY>");
props.document.write("<IMG SRC=\""+theURL+"\">");
props.document.write("<\/BODY><\/HTML>");
}
//-->
</script>
</head><body>
<a href=
"JavaScript:popUp('full/02.jpg','width=520,height=520,resizable=no,scrollbars=no,status=no, menubar=no')"> <img alt="View the painting" src="80s/02.jpg" width="80" height="63" border="0"></a>
</body>
</html>[
function popUp(theURL,features) {
props=window.open(theURL, 'poppage', features);
}
Also, I suggest using single quotes (') instead of double quotes (") when using document.write. That way you can use double quotes inside the string to your heart's content. For example:
document.write('<HTML><BODY style="border:0px">Hello</BODY></HTML>')
The only thing you have to escape with a backslash is apostrophes. For example:
document.write('<HTML><BODY style="border:0px">Hello, y\'all.</BODY></HTML>')
Hope this helps.
The fact is, the document.write()'s overwrite the initial display of the image and replace it with the document. There would be little noticeable difference in the displayed result. Perhaps some browsers would use different default margins on the bare image vs. the HTML page.
When using document.write(), you should finish with document.close(), otherwise the window will never finish loading.
[edited by: Rambo_Tribble at 2:14 am (utc) on May 23, 2004]
True redundancy would be if the URL in the window.open() loaded a page with the same markup that the document.write()'s produce.
Perhaps it would be more precise to say for the effect produced, the lines in question are superfluous.
The webmaster can load the image with either the <window.open> command *OR* with the <props.document.write> command. There is no need to do both.
The advantage of doing it the latter way is that more HTML code can be added (e.g., a directive to the user to how to close the window, code that closes the window if the user clicks the image, etc.).
The advantage of doing it the former way is that it's simple.
It's up to the webmaster which to choose, but the best choice is either one, not both.
The important point here is to provide a thorough and understandable explanation to the original inquirer as to what the code is doing and why. Hopefully that goal has been accomplished and this thread can be put to bed.
To close the window in your example, the code would be something like:
props.close();
Don't confuse the window.close() method above with the window.document.close() method mentioned earlier. The former will close the window, while the latter finishes the process of writting to the window.