By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,241 Members | 760 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,241 IT Pros & Developers. It's quick & easy.

Needs help in popup

P: n/a
Hi: Can any one please tell me what i make mistake in popup window?
When i click on the image it gives syntax error
Thanks.
function openWin(img) {
winId = window.open('','newwin','width=300,height=400');
winId.document.write('<body onLoad="if (window.focus)
window.focus()"><center>');
winId.document.write('<img src="' + img + '">');
winId.document.write('</center></body>');
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>'
This is the link. If you click on the first scrolling picture it gives
syntax error.

http://www.southeastneurology.com/testsite/
Jul 27 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
co*********@gmail.com wrote:
Hi: Can any one please tell me what i make mistake in popup window?
When i click on the image it gives syntax error
Thanks.
slideimages[0]='<a href="javascript:;" onClick="openWin("test7.jpg");
You've got nested double quotes in the onclick.

Why not just do this?

<a href="path_to_the_image" target="_blank">something</a>

The target = _blank will make it open a new window and is much less
liekly to get popup blocked.
Jul 27 '08 #2

P: n/a
co*********@gmail.com wrote:
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, <f8*******************@news.demon.co.uk>
Jul 27 '08 #3

P: n/a
Thanks. I try it but the menu is disappear also images are not
scrolling any more
http://www.southeastneurology.com/testsite/test.html

On Jul 27, 12:19*pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
colleen1...@gmail.com wrote:
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, <f806at$ail$1$8300d...@news.demon.co.uk>
Jul 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.