JS code inside frameset..

F

Frances Del Rio

can u put JS code inside a frameset? I have this, and it's not working,
even test alerts are ignored, in both browsers.. thank you..
Frances Del Rio


<frameset rows="90,*" border=0 frameborder="0" framespacing="0">
<frame name="header" src="header.html" scrolling="no" frameborder="0">
<script language="Javascript">
if(navigator.appName == "Netscape"){
alert('ha')
document.write("<frameset cols='120,*' frameborder='0' framespacing='0'>")
}
else {
alert('ha')
document.write("<frameset cols='112,*' frameborder='0' framespacing='0'>")
}
</script>

<frame name="nav" src="menu.html" scrolling="no" frameborder="0">
<frame name="main" src="check_puid.jsp" scrolling="auto" frameborder="0">
</frameset>
 
R

Ron

Frances said:
can u put JS code inside a frameset? I have this, and it's not
working, even test alerts are ignored, in both browsers.. thank you..
Frances Del Rio


<frameset rows="90,*" border=0 frameborder="0" framespacing="0">
<frame name="header" src="header.html" scrolling="no" frameborder="0">
<script language="Javascript">
if(navigator.appName == "Netscape"){
alert('ha')
document.write("<frameset cols='120,*' frameborder='0'
framespacing='0'>")
}
else {
alert('ha')
document.write("<frameset cols='112,*' frameborder='0'
framespacing='0'>")
}
</script>

<frame name="nav" src="menu.html" scrolling="no" frameborder="0">
<frame name="main" src="check_puid.jsp" scrolling="auto" frameborder="0">
</frameset>
script elements are not allowed in frameset elements ->
http://www.w3.org/TR/html401/present/frames.html#h-16.2.1 . Put your
script in the head element instead.
 
L

Lee

Frances Del Rio said:
bummer........


well, that's not of much use to me.. I need one frame with for Netscape
(N 4.7, I'm talking, hence the problem..) and another width for same
frame in IE.. thank you yr response.. Frances

Tested in Netscape 7 and IE6:

<html>
<head>
<script type="text/javascript">
var cols=(navigator.appName == "Netscape")?120:112;
var html=[
'<frameset rows="90,*" border=0 frameborder="0" framespacing="0">',
'<frame name="header" src="header.html" scrolling="no" frameborder="0">',
"<frameset cols='"+cols+",*' frameborder='0' framespacing='0'>",
'<frame name="nav" src="menu.html" scrolling="no" frameborder="0">',
'<frame name="main" src="check_puid.jsp" scrolling="auto" frameborder="0">',
'</frameset></frameset>'
];
document.write(html.join(""));
</script>
</head>
</html>
 
J

Jim Ley

Nice one. But as for legibility of the resulting code, one should rather use

document.write(html.join("\n"));

I'd recommend "" - the fewer redundant nodes you have in the DOM the
better - why would you be reading generated code anyway?

Jim.
 
T

Thomas 'PointedEars' Lahn

Lee said:
var cols=(navigator.appName == "Netscape")?120:112;
var html=[
'<frameset rows="90,*" border=0 frameborder="0" framespacing="0">',
'<frame name="header" src="header.html" scrolling="no" frameborder="0">',
"<frameset cols='"+cols+",*' frameborder='0' framespacing='0'>",
'<frame name="nav" src="menu.html" scrolling="no" frameborder="0">',
'<frame name="main" src="check_puid.jsp" scrolling="auto" frameborder="0">',
'</frameset></frameset>'
];
document.write(html.join(""));

Nice one. But as for legibility of the resulting code, one should rather use

document.write(html.join("\n"));

And note that Array object initializers are not supported by all script
engines, so you may want to use

var html = new Array(
...
);

as well. However, browser sniffing does not work:

<http://pointedears.de/scripts/test/whatami>


PointedEars
 
T

Thomas 'PointedEars' Lahn

Jim said:
I'd recommend "" - the fewer redundant nodes you have in the DOM the
better -

Generally, agreed. But it is unlikely that someone
will access the top frameset element with the DOM.
why would you be reading generated code anyway?

To see that it worked.


PointedEars
 
L

Lee

Thomas 'PointedEars' Lahn said:
var cols=(navigator.appName == "Netscape")?120:112;
var html=[
'<frameset rows="90,*" border=0 frameborder="0" framespacing="0">',
'<frame name="header" src="header.html" scrolling="no" frameborder="0">',
"<frameset cols='"+cols+",*' frameborder='0' framespacing='0'>",
'<frame name="nav" src="menu.html" scrolling="no" frameborder="0">',
'<frame name="main" src="check_puid.jsp" scrolling="auto" frameborder="0">',
'</frameset></frameset>'
];
document.write(html.join(""));

Nice one. But as for legibility of the resulting code, one should rather use

document.write(html.join("\n"));

And note that Array object initializers are not supported by all script
engines, so you may want to use

var html = new Array(
...
);

as well. However, browser sniffing does not work:


1. During testing, I did join a newline, and alerted the result.
I changed it to "" and deleted the alert for release.

2. This is probably the first time I've used browser sniffing,
and did so only because the OP's requirement was to have a
different frame size in Netscape, specifically. Personally,
I would try to avoid such a requirement.
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top