...

View Full Version : setting a property that has only a getter



tpeck
01-02-2011, 12:56 PM
I am sorry the following code is a bit of a mouthful, but I can't find a better way to display the problem.

The code works as expected in Chrome, but not in IE and FF. In IE the error is "Object doesn't support this action" and in FF "setting a property that has only a getter". In Chrome there is no error in the console.

There are three javascript <script>...</script>s that exist to display a <td> row in a table with a particular graphic depending on the screen width.

The odd thing is that in both IE and FF (and of course Chrome), the first two scripts display perfectly well.

Why does the third <script> produce an error?

It has exactly the same form as the two before it.

I can only guess it has something to do with where it occurs :confused:

Googling the FF error, it has something to do with trying to set a read-only property, but then why do the first two <scripts> work? They are no different (at least I can't see a difference.)



<table border="0" width="100%" cellpadding="0" style="border-collapse: collapse" id="table3768">
<script>
if (screen.width > 1280) {
document.write("<td valign=\"top\" background=\"..\/..\/img\/lesson2.gif\" width=\"840\" height=\"301\">");
}
else {
document.write("<td valign=\"top\" background=\"..\/..\/img\/lesson.gif\" width=\"369\" height=\"301\">");
}
</script>
<p>&nbsp;</p>
<div align="left">
</table>
<table border="0" style="border-collapse: collapse" cellpadding="15">
<tr>
<td width="40">&nbsp;</td>
<script>
if (screen.width > 1280) {
document.write("<td width=\"300\">");
}
else {
document.write("<td width=\"165\">");
}
</script>
<font face="Trebuchet MS" color="#808000">Today's lesson is about setting
goals...</font></td>
</tr>
</table>
</div>
</td>
<td rowspan="3">
<table border="0" cellspacing="0" style="border-collapse: collapse" cellpadding="0" id="table3920">
<tr>
<td><img border="0" src="../../img/teltopw.jpg" width="550" height="9"></td>
</tr>
<tr>
<td background="../../img/telbarw.jpg">
<p align="center">
<iframe name="ITV" src="lesson1TV.html" marginwidth="0" marginheight="0" scrolling="no" border="0" frameborder="0" width="480" height="376">
Your browser does not support inline frames or is currently configured
not to display inline frames.
</iframe></p>
</td>
</tr>
<tr>
<td><img border="0" src="../../img/telbotw.jpg" width="550" height="11"></td>
</tr>
</table>
</td>
<td align="center">
<a target="_blank" href="http://www.apple.com/quicktime/download/">
<img border="0" src="../../img/quicktimeani.gif" width="129" height="184"></a></td>
</tr>
<tr>
<script>
if ((screen.width = 1440) || (screen.width = 1400)) {
document.writeln("<td valign=\"top\" width=\"100%\" background=\"\/images\/101online\/listening\/lesson16\/notebot2.gif\" width=\"450\" height=\"50\">");
}
else if (screen.width <= 1280) {
document.writeln("<td valign=\"top\" width=\"100%\" background=\"\/images\/101online\/listening\/lesson16\/notebot.gif\" width=\"294\" height=\"50\">");;
}
</script>
</td>
<td valign="bottom">&nbsp;</td>
</tr>
<tr>
<td valign="bottom" width="100%">
<div align="right">
<table border="0" cellpadding="5" style="border-collapse: collapse" id="table3926">
<tr>
<td align="center">
<a onmousedown="soundManager.play('piano','../../media/mp3/piano.mp3'); return true;" href="javascript: goFull('FULLSCREEN/lesson1full.html','info','width=1020,height=760,left=0,top=0,toolbar=no,scrollbars=no,status=no,dire ctories=no,menubar=no,location=no,resizable=no');">
<img src="../../img/poster1ani.gif" border="0" width="95" height="29"></a>
<b><font size="1" face="Arial" color="#000080">&nbsp;ON DISK</font></b></td>
<td align="center"><b><font size="1" face="Arial" color="#000080">OR
</font></b>&nbsp;<a onmousedown="soundManager.play('piano','../../media/mp3/piano.mp3'); return true;" href="javascript: goFull('CDRIVE/lesson1Cfull.html','info','width=1020,height=760,left=0,top=0,toolbar=no,scrollbars=no,status=no,dir ectories=no,menubar=no,location=no,resizable=no');"><img src="../../img/poster7.bmp" border="0" width="53" height="30"></a>
<b><font size="1" face="Arial" color="#000080">&nbsp;DRIVE</font></b></td>
</tr>
</table>
</div>
</td>
<td valign="bottom">
<iframe name="sounds" src="../../pagesounds.html" width="160" height="66" marginwidth="1" marginheight="1" scrolling="no" border="0" frameborder="0">
Your browser does not support inline frames or is currently configured not to display
inline frames.
</iframe></td>
</tr>
</table>


Any light on this would be most welcome!

vwphillips
01-02-2011, 02:31 PM
if ((screen.width == 1440) || (screen.width == 1400)) {

tpeck
01-02-2011, 11:31 PM
Thanks Vic. Another egregious error of mine. Still, it's odd that Chrome is forgiving of this one.

Old Pedant
01-04-2011, 12:23 AM
Yes, it does seem odd. I'd rate that as a bug in Chrome.

Clearly, screen.width can't possibly be a user-modifiable value. So it's just meaningless to assign a value to screen.width. I suppose you can argue that "meaningless" isn't the same as "causes an error", but still... It's an odd choice by the Chrome team to not barf on that.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum