Hi,
so einfach geht das nicht!
Selbst wenn Dein Beispiel mit dem document. Zeugs funktionieren würde, .textAlign ist nichts anderes als der Javascript-Zugriff auf das CSS-Element text-align. Das bedeutet, der Code ist völlig überflüssig, da man text-align einfach statisch auf center setzen kann, ohne irgend ein Script benutzen zu müssen, d.h. #mxbox { text-align: center } ... Das bringt aber nicht den gewünschten Effekt.
Was Du willst, ist nur sehr, sehr, sehr viel komplexer zu realisieren, etwa so:
... blabla ...
<body onload="init()">
<div id="boxes">
<div id="box1">Hallo Welt!</div>
<div id="box2">Test</div>
</div>
... blabla ...
function init()
{
centerLayer(getObj("boxes"), 750, 450);
showLayer(getObj("boxes"));
}
dom = (document.getElementById) ? true : false;
ie4 = (document.all) ? true : false;
ns4 = (document.layers) ? true : false;
op = (window.opera) ? true : false;
function getObj(name)
{
if(ie4) return eval('document.all.'+name);
if(ns4) return findLayer(name, document);
if(dom) return document.getElementById(name);
return null;
}
function findLayer(name, doc) // NS4
{
for (var i=0; i<doc.layers.length; i++)
{
var layer = doc.layers[i];
if (layer.name == name) return layer;
if (layer.document.layers.length > 0)
{
var layer = findLayer(name, layer.document);
if (layer != null) return layer;
}
}
return null;
}
function hideLayer(obj)
{
if(ns4) obj.visibility = "hide";
if(ie4 || dom) obj.style.visibility = "hidden";
}
function showLayer(obj)
{
if(ns4) obj.visibility = "show";
if(ie4 || dom) obj.style.visibility = "visible";
}
function centerLayer(obj, width, height) // V2.0 by DR
{
if (ie4 || dom) // No NS4 support because nested layer bug
{
winWidth = getWinWidth();
winHeight = getWinHeight();
leftMid = winWidth / 2 - width / 2;
topMid = winHeight / 2 - height / 2;
if(leftMid < 0) leftMid = 0;
if(topMid < 0) topMid = 0;
posLayer(obj, leftMid, topMid);
}
}
function posLayer(obj, left, top) // V2.0 by DR
{
if (ie4 || dom) {
style = obj.style;
style.left = left+"px"; style.top = top+"px";
}
else if (ns4) {
style = obj;
style.left = left; style.top = top;
}
}
function getWinWidth() // based on a script by projectseven.com (PVII)
{
if (window.innerWidth) { w = window.innerWidth; } // ns4
else if (document.body)
{
w = document.body.clientWidth;
if (document.body.offsetWidth == w && document.documentElement && document.documentElement.clientWidth)
{
w = document.documentElement.clientWidth;
}
}
return w;
}
function getWinHeight() // based on a script by projectseven.com (PVII)
{
if (window.innerWidth) { h = window.innerHeight; } // ns4
else if(document.body)
{
h = document.body.clientHeight;
if (document.body.offsetHeight == h && document.documentElement && document.documentElement.clientHeight)
{
h = document.documentElement.clientHeight;
}
}
return h;
}
function getWinWidth_Resized() // Example from SelfHTML
{
if (window.innerWidth) return window.innerWidth;
else if (document.body && document.body.offsetWidth) return document.body.offsetWidth;
else return 0;
}
function getWinHeight_Resized() // Example from SelfHTML
{
if (window.innerHeight) return window.innerHeight;
else if (document.body && document.body.offsetHeight) return document.body.offsetHeight;
else return 0;
}
function P7_OpResizeFix(a) { // v1.1 by PVII, edited by DR/IG
var agent = navigator.userAgent.toLowerCase();
var op = (window.opera) ? true : false;
var op7 = (agent.indexOf("opera 7") != -1 || agent.indexOf("opera/7") != -1);
if (!op || op7) {
return;
}
if (!document.p7oprX) {
document.p7oprY = window.innerWidth;
document.p7oprX = window.innerHeight;
document.onmousemove = P7_OpResizeFix;
}
else {
if (document.p7oprX) {
var k = document.p7oprX - window.innerHeight;
var j = document.p7oprY - window.innerWidth;
if (k>1 || j>1 || k<-1 || j<-1) {
document.p7oprY = window.innerWidth;
document.p7oprX = window.innerHeight;
location.reload();
}
}
}
}
P7_OpResizeFix();
function IG_reloadPage() { // Requires dhtml.js (IG Lib 3.0 beta)
var pW = getWinWidth_Resized();
var pH = getWinHeight_Resized();
if (reload_init) {
document.IG_pageWidth = pW;
document.IG_pageHeight = pH;
window.onresize = IG_reloadPage;
reload_init = false;
}
else {
if (pW != document.IG_pageWidth || pH != document.IG_pageHeight) {
// location.reload();
window.history.go(0);
}
}
}
reload_init = true;
IG_reloadPage();