body onload 控制窗口大小 html,如何实现在调整浏览器窗口大小时缩放的网页?

感谢所有的建议!看起来我必须做的丑陋的东西是必要的。以下工作(在我的机器上,无论如何)在IE和FireFox中。我可能会在以后为CodeProject.com做一篇文章;-)

这个javascript进入< head>部分:

var tmout = null;

var mustReload = false;

function Resizing()

{

if (tmout != null)

{

clearTimeout(tmout);

}

tmout = setTimeout(RefreshAll,300);

}

function Reload()

{

document.location.href = document.location.href;

}

//IE fires the window's onresize event when the client area

//expands or contracts, which causes an infinite loop.

//the way around this is a hidden div set to 100% of

//height and width, with a guard around the resize event

//handler to see if the _window_ size really changed

var windowHeight;

var windowWidth;

window.onresize = null;

window.onresize = function()

{

var backdropDiv = document.getElementById("divBackdrop");

if (windowHeight != backdropDiv.offsetHeight ||

windowWidth != backdropDiv.offsetWidth)

{

//if screen is shrinking, must reload to get correct sizes

if (windowHeight != backdropDiv.offsetHeight ||

windowWidth != backdropDiv.offsetWidth)

{

mustReload = true;

}

else

{

mustReload = mustReload || false;

}

windowHeight = backdropDiv.offsetHeight;

windowWidth = backdropDiv.offsetWidth;

Resizing();

}

}

< body>像这样开始:

style="width:100%; clear:both; height: 100%; margin: 0;

padding: 0; position:absolute; top:0px; left:0px;

visibility:hidden; z-index:0;">

DIV向左浮动以进行布局。我不得不将高度和宽度设置为完全量的百分比(例如,99.99%,59.99%,39.99%),以防止浮动包裹,可能是由于DIV上的边界。

最后,在内容部分之后,另一个javascript块来管理刷新:

var isWorking = false;

var currentEntity = ;

//try to detect a bad back-button usage;

//if the current entity id does not match the querystring

//parameter entityid=###

if (location.search != null && location.search.indexOf("&entityid=") > 0)

{

var urlId = location.search.substring(

location.search.indexOf("&entityid=")+10);

if (urlId.indexOf("&") > 0)

{

urlId = urlId.substring(0,urlId.indexOf("&"));

}

if (currentEntity != urlId)

{

mustReload = true;

}

}

//a friendly please wait... hidden div

var pleaseWaitDiv = document.getElementById("divPleaseWait");

//an example content div being refreshed via AJAX PRO

var contentDiv = document.getElementById("contentDiv");

//synchronous refresh of content

function RefreshAll()

{

if (isWorking) { return; } //no infinite recursion please!

isWorking = true;

pleaseWaitDiv.style.visibility = "visible";

if (mustReload)

{

Reload();

}

else

{

contentDiv.innerHTML = NAMESPACE.REFRESH_METHOD(

(currentEntity, contentDiv.offsetWidth,

contentDiv.offsetHeight).value;

}

pleaseWaitDiv.style.visibility = "hidden";

isWorking = false;

if (tmout != null)

{

clearTimeout(tmout);

}

}

var tmout2 = null;

var refreshInterval = 60000;

//periodic synchronous refresh of all content

function Refreshing()

{

RefreshAll();

if (tmout2 != null)

{

clearTimeout(tmout2);

tmout2 = setTimeout(Refreshing,refreshInterval);

}

}

//start periodic refresh of content

tmout2 = setTimeout(Refreshing,refreshInterval);

//clean up

window.onunload = function()

{

isWorking = true;

if (tmout != null)

{

clearTimeout(tmout);

tmout = null;

}

if (tmout2 != null)

{

clearTimeout(tmout2);

tmout2 = null;

}

难看,但它有效 - 我猜它真正重要;-)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值