I have an html frameset <frameset name="home" id="home" ...>
and
I'd like to append a new frame to it using JS. So I wrote this piece of code:
var newFrame = document.createElement("frame");
newFrame.id = "myNewFrame";
newFrame.name = "myNewFrame";
newFrame.src = "/myRelativeUrl.html";
var domFrameset = document.getElementById("home");
if (domFrameset) {
domFrameset.appendChild(newFrame);
}
It works as expected in modern browsers but not in IE8. It creates the frame tag, but does not perform the request.
After one day of research and no responses I was convinced there was no solution for this issue.
But finally I've come up with a solution that solves the problem:
When working with <frameset>
and <frame>
, you need to apply a rows attribute to the frameset in order to display the frames correctly within it. You must edit this attribute before stablishing the SRC param of the new frame!
The HTML:
<frameset name="home" rows="95,*">
<frame name="frame1" src="/menu.html"/>
<frame name="frame2" src="/main.html"/>
</frameset>
Adding a new frame using JS (for IE8 too):
var newFrame = document.createElement("frame");
newFrame.id = "myNewFrame";
newFrame.name = "myNewFrame";
var domFrameset = document.getElementById("home");
if (domFrameset) {
domFramset.rows = "95,*,100"; //<-- This is the key
domFrameset.appendChild(newFrame);
newFrame.src = "/myRelativeUrl.html"; //<-- Set SRC after appending
}
Hope this can help someone suffering same problem-