Forum Moderators: open
function showinformation(filetooutput)
{
bigtable=document.createElement('table');
bigtable.style.position="absolute";
bigtable.style.top=0;
bigtable.width=getInsideWindowWidth()-20;
bigtable.setAttribute('height',getInsideWindowHeight()-20);
tablebody=document.createElement('tbody');
mainrow=document.createElement('tr');
maintd=document.createElement('td');
subtable=document.createElement('table');
subtable.border="1";
subtable.align="center";
subbody=document.createElement('tbody');
subtr=document.createElement('tr');
subtd=document.createElement('td');
subtd.width="800";
subtd.height="650";
subtd.innerHTML="<iframe src='"+filetooutput+"' frameborder='0' scrolling='no' style='border-width:0px;width:800px;height:610px;'></iframe><br>Привет</td>";
subtr.appendChild(subtd);
subbody.appendChild(subtr);
subtable.appendChild(subbody);
maintd.appendChild(subtable);
mainrow.appendChild(maintd);
tablebody.appendChild(mainrow);
bigtable.appendChild(tablebody);
document.body.appendChild(bigtable);}
Alternatively, you could move the element every time the user resizes it, by doing the following:
<HEAD>
<script language=javascript>
function correctDeadCenter(elemnt){
elemnt.style.position="absolute";
elemnt.style.top=eval(eval(eval(document.body.clientHeight)/2)-eval(eval(elemnt.height)/2));
elemnt.style.left=eval(eval(eval(document.body.clientWidth)/2)-eval(eval(elemnt.width)/2));
}
</script>
</HEAD>
<BODY onresize="correctDeadCenter(document.images[0])">
<img src="boy.gif" width=300 height=300>
<script language=javascript>
correctDeadCenter(document.images[0])
</script>
</BODY>
Keep in mind, this centers and middles the element, although it doesn't look it. You may want to subtract a couple of pixels.
elm.style.left = (document.body.clientWidth - elm.offsetWidth)/2 +'px';
elm.style.top = (document.body.clientHeight - elm.offsetHeight)/2 +'px'; (..it's still IE-specific though)
see: eval is evil [blogs.msdn.com] ;)
window.onresize = function(){
correctDeadCenter(elementRef);
}
A few things about the code you originally posted:
- I'm not sure you need the inner table.
- To save on messy statements, it is legal to write things like:
document.createElement('<td width="200" height="200">');
You can also create and append in one statement, to avoid using intermediary variables..
var ref_to_created_child = parentRef.appendChild(document.createElement('<td width="200" height="200">'));
- You may prefer to use specialised table methods,
insertRow, insertCell . [msdn.microsoft.com...]
Attributes can be included with the sTag as long as the entire string is valid HTML. You should do this if you wish to include the NAME attribute at run time on objects created with the createElement method.
Well, that's what MS says. Pretty sure it's standard.
(never can tell, myself)