javascript - Jquery 加载图像 - 处理网络浏览器中的后退/前进按钮

标签 javascript jquery html css loading

我使用以下方法在加载页面时显示加载图像,以通知用户加载操作正在进行中。如果我在网络浏览器中按“后退”按钮,有时页面会以加载图像开始,然后页面就会卡住。我想确保如果用户在网络浏览器中按下后退/前进按钮,则要显示加载图像。

正在使用的方法。

Javascript:

<script language="javascript" type="text/javascript">
$(document).ready(function (){
  //This line below would hide the div when the page load by default
  $('#loading').hide();

  //This would display when the user clicks the button
  $('#buttonID').click(function (){
    if( $('#search_string').val().length !== 0 ) {    
    $('#loading').show();
    }
  });
   $('a.la').click(function (){
    $('#loading').show();
 });
});
$(window).load(function() {
$('#loading').hide();
});
</script>

CSS

#loading {
   width: 100%;
   height: 100%;
   top: 0;
   left: 0;
   position: fixed;
   display: block;

   z-index: 99;
   text-align: center;
}

#loading-image {
  position: absolute;
  top: 160px;
  left: 130px;
  z-index: 100;
}

HTML

<button id='buttonID' type="submit"></button>
<a class="la" href="search.php">Some text</a><br>

最佳答案

最好听听浏览器并以这种方式编写您的应用程序,这样这些事情就变得无关紧要了。

而且浏览器正在将越来越多的东西锁定到客户端 javascript 应用程序也是事实,因此您的应用程序很可能在(少数)浏览器升级后失败

这里有很好的解释:HTML 5 History Spec 并在此处演示:History Demo

关于javascript - Jquery 加载图像 - 处理网络浏览器中的后退/前进按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40466706/

相关文章:

javascript - 用javascript生成菜单?

jquery - 仅当上一个元素关闭时,单击同一元素才能关闭和打开下拉列表

javascript - 如何在 Bootstrap Material 设计的输入文本中制作标签支持?

javascript - 使用react-router的历史记录,有没有办法在不使用push()或replace()的情况下返回到之前渲染的特定页面?

javascript 删除空格回车符

javascript - 打开后如何更改bootstrap modal-body Height?

javascript - underscore.js 减少错误?与 Ruby 的行为不同?

javascript - Jquery 等待 AJAX 调用完成

jQuery 查询数据库

html - 使用 CSS 进行响应式设计的布局样式