Opera frames BUG?

2019-03-02 02:03发布

问题:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>

<script>
var G = function (id) {return document.getElementById(id); }
var C = function (tag) {return document.createElement(tag); }

window.onload = function ()
{
var f = C('frame');
f.name = 'my';
f.id = 'my';
f.src = 'about:blank';
G('content').appendChild(f);

alert('test');   

window.frames['my'].document.write('Loading...');
}
</script>

<frameset id="content" rows="100%,*" cols="*" frameborder="no" border="0" framespacing="0">
</frameset>
</html>

alert('test'); // Remove this line, Opera load is not successful. why? IE Firefox Chrome Safari No problem...

回答1:

Yay, another about:blank load timing problem.. It's really hard to get this right: http://hsivonen.iki.fi/about-blank/

Anyway, when Opera does a simple thing like this differently from everybody else it's by definition a bug in Opera. I have reported "CORE-45144 - window.frames collection not immediately updated when FRAME is appended to FRAMESET through DOM (appendChild and friends)" so it should be fixed in due course. There is an on-going maintenance project that might solve this issue among others, results won't make it for Opera 12 but quite likely the next majorish update.

If you need a workaround, just use setTimeout() with some small timeout value to delay the code that writes to the new frame slightly.

Thanks for bringing this to my attention :-)