function openWin(img) {
winId = window.open('','newwin','width=300,height=400');
I hope `winId' is declared somewhere, else you would attempt to augment an
object in the scope chain, with supposedly unexpected results.
winId.document.write('<body onLoad="if (window.focus)
window.focus()"><center>');
You need to test whether `winId' actually refers to a Window object before
you use it.
You forgot to open a document stream for writing.
If you generate a popup document dynamically, you need to generate all of
it, including DOCTYPE declaration, `html' element, and `head' element.
`center' is a deprecated element; CSS turns 11 this year.
winId.document.write('<img src="' + img + '">');
winId.document.write('</center></body>');
Consecutive calls of document.write() are error-prone as you are writing
incomplete elements. They are also quite inefficient.
winId.document.close();
}
slideimages[0]='<a href="javascript:;" onClick="openWin("test7.jpg");
return false"><img src="test7.jpg" border="0" width="200"
height="200"></img></a>'
The link does not degrade gracefully, it will not work without scripting
although it could. `"' already delimit the attribute value which is why you
cannot use it (not even escaped) in the value itself; ...
This is the link. If you click on the first scrolling picture it gives
syntax error.
... else the value is likely to end at the next `"' which would result in
script code like
openWin(
which is one reason for the syntax error you observed.
Also, the `alt' attribute is required for the `img' element. The `img'
element's end tag is forbidden in HTML, and probably you don't want to use
XHTML. Furthermore, ETAGOs within `script' elements must be escaped.
Summarized, *for a start*:
function openWin(img)
{
// add proper feature tests here
var win = window.open('', 'newwin',
'width=300,height=400,resizable,scrollbars');
if (win && !win.closed && win.document && win.document.open
&& win.document.write && win.document.close)
{
var s = new Array(
'<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"',
' "
http://www.w3.org/TR/html4/strict.dtd">',
'<html>',
' <head>',
' <meta http-equiv="Content-Type" content="text/html;'
+ ' charset=utf-8">',
' <title>' + img + '<\/title>',
' <\/head>',
' <body onload="if (window.focus) window.focus()"',
' style="margin: 0; padding: 0; text-align: center"',
' ><img src="' + img + '" alt="' + img+ '"><\/body>',
'<\/html>'
).join("\n");
winId.document.open("text/html; charset=utf-8");
winId.document.write(s);
winId.document.close();
}
return !win;
}
<a href="test7.jpg" onclick="return openWin(this.href)"
><img src="test7.jpg" alt="Test 7"
style="border: 0; width: 200px; height: 200px"></a>
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <
[email protected]>