Forum Moderators: open

Message Too Old, No Replies

IE6 and writeln problem

Function to create window content stopped working

         

ravensden

8:56 am on Apr 17, 2003 (gmt 0)

10+ Year Member



This is my first post here. Please forgive me if my etiquette is off.

Our village site is largely a big photo album. For the last couple of years I've been having each page of thumbnails call a common js file so that clicking a thumbnail opens a new window and creates content for that new window "on the fly". Can't remember where I found the code originally. It worked fine upto IE5.5 but visitors using IE6 now tell me that the new window has no content. I think it must be to do with how IE6 treats the writeln function.

The following is a test file combining the relevant part of the code in the js file and some dummy page-specific variables to show the idea:

<html>
<script language ="Javascript">
<!--

var thisTitle="This is a fullscreen photo page";
var bkGnd='somebackground.gif';
var linkColor='blue';
var hipicHeight='650';

function enlarge(whichpic) {
top.winRef=window.open('','BigPic',
+',menubar=0'
+',toolbar=0'
+',status=0'
+',scrollbars=0'
+',resizable=0')

top.winRef.document.writeln(
'<html>'
+'<head>'
+'<title>'+thisTitle+' - Right-click background to print</title>'
+'<script language="Javascript">'
+'if(navigator.appName=="Microsoft Internet Explorer") {'
+'aw = screen.availWidth;'
+'ah = screen.availHeight-22;'
+'window.moveTo(0, 0);'
+'window.resizeTo(aw, ah);'
+'}'
+'<'
+'/script>'
+'</head>'
+'<body background='+bkGnd+' link='+linkColor+' vlink='+linkColor+' alink='+linkColor+' onLoad="self.focus()">'
+'<table align=center width=100% height=100% border=0>'
+'<tr>'
+'<td align=center>'
+'<a href ="" onClick="window.close()" title="Click photo to close window">'
+'<img src='+whichpic+'.jpg align=center height="'+hipicHeight+'" border=3>'
+'</a>'
+'</td>'
+'</tr>'
+'</table>'
+'</body>'
+'</html>'
)

top.winRef.document.close()

}
//-->
</script>

</head>

<body>
<p align="center">
<a href="javascript:enlarge('1')" onClick="if(this.blur)this.blur()"><img src=thumb1.jpg border=3></a>
</p>
</body>
</html>

I'd be hugely grateful if someone could spot what's wrong!

grahamstewart

9:25 am on Apr 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi ravensden,

Welcome to Webmasterworld [webmasterworld.com]

One thing that is wrong is the script tag.
It should read <script language="Javascript" type="text/javascript"> (the language attribute is actually deprecated now, but I suggest you leave it in).

Also all your attributes should have quotes around them. So lines like..

+'<table align=center width=100% height=100% border=0>'

should actually read..

+'<table align="center" width="100%" height="100%" border="0">'

Don't know if any of these are the source of your problem, but they won't be helping thats for sure. ;)

ShawnR

10:22 am on Apr 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Graham is correct if you want to be standards compliant, etc. However, those things won't concern IE; IE is very forgiving that way.

"...visitors using IE6 now tell me..."
I suggest you test for yourself in the first instance. I suspect you will find that it works fine for you, because I can't see anything wrong with the code myself. There are a couple of possibilities I can think of:
  • Your visitors might have installed software to stop pop-up spam adverts, which your code might be trigerring.
  • Your visitors might have Javascript disabled

To make the code cope with the situation of Javascript turned off, you could change

<a href="javascript:enlarge('1')" onClick="if(this.blur)this.blur()"><img src=thumb1.jpg border=3></a>

to something like

<a href="1.jpg" target="BigPic" onClick="javascript:enlarge('1'); if(this.blur)this.blur(); return false;"><img src=thumb1.jpg border=3></a>

Shawn

ravensden

5:11 pm on Apr 17, 2003 (gmt 0)

10+ Year Member



Thanks folks.

I've emailed a sample page with Graham's suggested amendments to one of the folks having the problem to see if it fixes it. (He lives nearby so we can discuss things easily! At the moment my backup PC is down and I don't really want to upgrade this one to IE6 whilst that's the case.)

I don't think it's a case of folks having pop-up killers installed or javascript turned off, 'cos the window.open bit still works. i.e. the new window opens for them but is empty and titled the default "about blank" ....

DrDoc

7:12 pm on Apr 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to Webmaster World! :)

Since you suspect document.writeln to be the problem, have you tried using only document.write?

Also, the window reference top.winRef... Try replacing any references to the window with the window name (which is "bigPic"). So, instead of top.winRef.document.writeln, try BigPic.document.writeln.

grahamstewart

10:28 pm on Apr 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



+'<'
+'/script>'

This seems a little odd too. Shouldn't it just be +'</script>'

ShawnR

11:41 pm on Apr 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



'...new window opens for them but is empty and titled the default "about blank"...'

That is exactly the symptoms I have seen Norton Internet Security do to *some* sites when the Ad blocking feature is turned on. Not saying that is it; just don't rule it out...

"...Shouldn't it just be +'</script>'..."
I agree that

+'<'
+'/script>'

is not elegant, but it will work.

I just copied the code into an empty document, and opened it with IE6, and it seems to work OK for me, so I'm pretty certain that whatever the problem is, it is not just IE6.

Shawn

ravensden

2:50 pm on Apr 19, 2003 (gmt 0)

10+ Year Member



Hi folks and many thanks for all the help.

It seems that my lazy omission of quotes around attributes was the problem, since including them seems to have fixed things. Looks as though IE6 is a little less forgiving in this area than earlier versions! Doesn't explain how the original code seemed to work for Shawn though ...

One other strange thing: adding the quotes did the job, as I say, except that the "tooltip" prompting visitors to close the "enlargement" window still didn't work in IE6.

Original code was:

+'<td align=center>'
+'<a href ="" onClick="window.close()" title="Click photo to close window">'
+'<img src='+whichpic+'.jpg align=center height="'+hipicHeight+'" border=3>'
+'</a>'
+'</td>'

I thought that this positioning of the title inside the anchor tag was W3C compliant.

Anyhow, I added a pair of span tags and moved the title there and that fixed that issue. That bit now looks like this:

+'<td align="center">'
+'<span title="Click photo to close window"><a href ="" onClick="window.close()">'
+'<img src='+whichpic+'.jpg align="center" height="'+hipicHeight+'" border="3">'
+'</a></span>'
+'</td>'

Once again, thanks a lot.

DrDoc

3:19 pm on Apr 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Shouldn't it just be +'</script>'

No, some browsers will terminate the script otherwise...

ShawnR

1:34 am on Apr 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



"...Looks as though IE6 is a little less forgiving..."

Weird... Perhaps my IE6 is more up to date with updates. My version is 6.0.2800.1106.......

Well done on solving it!

Shawn