If there a more proper DOM oriented way to go about this?
Thanks,
Csaba Gabor from Vienna
The below works as expected in FF 1.5, but not in IE 6:
<html>
<head><title>Target test</title></head>
<body onLoad='loaded()'>
<form method=get target=myFrame action="http://google.com">
<button type=submit accessKey=u>S<u>u</u>bmit</button>
</form>
<script type='text/javascript'>
function loaded() {
var myFrame = document.createElement("IFRAME");
myFrame.style.width = '100%';
myFrame.style.height = '7cm';
myFrame.id = 'myFrame';
myFrame.name = 'myFrame';
document.body.appendChild(myFrame); }
</script>
</body>
</html>
I don't think so. You need IE specific approaches such as using
innerHTML as you have already found or passing in the attribute in the
createElement method e.g.
var myFrame = document.createElement('<iframe name="myFrame">');
See the documentation:
http://msdn.microsoft.com/en-us/library/ms534184(VS.85).aspx
As the latter does not work outside of IE I would go with creating the
iframe by setting the innerHTML of another element and then extract its
child node.
--
Martin Honnen
http://msmvps.com/blogs/martin_honnen/
Because you are accessing the element object, not the corresponding Window
object.
> I can bypass the problem by putting in
> a DIV and then setting the innerHTML of the DIV to
> "<IFRAME name=... >target IFRAME</IFRAME>"
> but this is really not very nice.
>
> If there a more proper DOM oriented way to go about this?
You are using the DOM already, just not the W3C DOM.
> [...]
> The below works as expected in FF 1.5, but not in IE 6:
Well, it's not Valid to begin with.
> <html>
> <head><title>Target test</title></head>
> <body onLoad='loaded()'>
> <form method=get target=myFrame action="http://google.com">
method=get is superfluous. Should be target="myFrame".
> <button type=submit accessKey=u>S<u>u</u>bmit</button>
> </form>
>
> <script type='text/javascript'>
> function loaded() {
> var myFrame = document.createElement("IFRAME");
Mapping the case before the call like here might indeed be a good idea.
> myFrame.style.width = '100%';
> myFrame.style.height = '7cm';
You can't be serious.
> myFrame.id = 'myFrame';
> myFrame.name = 'myFrame';
> document.body.appendChild(myFrame);
And then (as thoroughly explained in an article of Richard Cornford, IIRC):
window.frames["myFrame"].name = "myFrame";
Case closed.
PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
No, you don't. In fact, the MSHTML quirk is easily detectable and
fixable; one does not even need to resort to browser sniffing:
var s = "foo";
var f = window.frames[s];
if (f.name != s) f.name = s;
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16