Needs help in popup

C

colleen1980

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/
 
S

Stevo

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.
 
T

Thomas 'PointedEars' Lahn

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
 
C

colleen1980

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

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]>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,120
Latest member
ShelaWalli
Top