gpt4 book ai didi

javascript - 内容处理 : DIV vs. 全屏

转载 作者:行者123 更新时间:2023-11-28 14:56:58 25 4
gpt4 key购买 nike

假设一个简单的应用程序,其顶部具有以下导航(伪代码):

<a href="?action=new">New</a>
<a href="?action=search">Search</a>

下面有不同的部分,即"new"面具:

<div id="condition">
<form>
<input type="text" name="Login" />
<input type="text" name="First" />
<a href="javascript:performSearch()">Perform search</a>
</form>
</div>
<div id="results"
<table>
..
</table
</div>

让我们假设 session 超时并且用户点击...

  • :从服务器返回的内容将“全屏”加载,并且必须包括页眉/页脚等
  • 执行搜索:内容将显示在结果中 DIV:应该只是一条简短的错误消息

问题:

  • 有没有办法通过 JavaScript(在“​​error.html”中)识别当前内容是加载到 DIV 还是“全屏”?
  • 我应该总是返回一个跨越整个浏览器窗口的元素吗?
  • 或者是否有其他方法来处理这种情况?

如有任何建议或想法,我们将不胜感激。

最佳答案

is there a way to identify via JavaScript (in the "error.html") if the current content is loaded into a DIV or "fullscreen"? Or is there a different way to handle this situation?

我认为这真的不重要!

不能 100% 确定这会回答您的问题,但我会这样做:

每个 页面中都有一个不可见的error div。

<div id="errordiv" style="display: none">Error!</div>

让它跨越整个浏览器窗口。

div#errordiv
{
position: fixed; // Works everywhere except IE 6
left: 0px; top: 0px; right: 0px; bottom: 0px;
background-color: white; // or whatever

}

如果在运行 JavaScript 时发生错误(无论在什么情况下!),使错误 div 可见:

document.getElementById("errordiv").style.display = "block";

添加错误信息

document.getElementById("errordiv").style.innerHTML= 
"<h1>Error</h1>An error has occurred.....";

(当然,您会将所有这些包装到一个中央 showError() 函数中)

如果在服务器端处理期间发生错误,从一开始就使其可见(如何做到这一点,因语言而异)。

关于javascript - 内容处理 : DIV vs. 全屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3459735/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com