同时浏览当前页面preLOAD第二页 [英] Preload second page while viewing the current page

查看:106
本文介绍了同时浏览当前页面preLOAD第二页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说我的网站有5页的内容。是否有可能以preLOAD,而访问者查看第一页下两页。所以,当他们点击链接到第二或第三页时,它会立即出现。

Let's say my website has 5 pages of content. Is it possible to preload the next two pages while visitor is viewing the first page. So that when they click the link to 2nd or 3rd page, it will appear immediately.

推荐答案

当然,你可以有一些invisble容器是这样的:

Sure, you can have some invisble containers like this:

HTML

<div id="page">
  <a href="page2.html" id="page2-link">Go second page</a>
</div>
<div id="page2">
</div>

CSS

#page2 { display:none }

Javascript的

然后,当在JavaScript的preLOAD后,第二页已经被加载,并把它放在invisble容器:

Then when at the javascript preload the second page after it has been loaded and put it on the invisble container:

$().ready(function(){
  $('#page2').load('page2.html #page');
});

和链接被点击的时候就显示出隐藏的容器中选择页,并删除其他,或者只是隐藏当用户​​想要返回或它不会再次加载的东西。

And when the link is clicked just show the hidden container with selected page and remove the other, or just hide it to not load again when user wants to return or something.

$().ready(function(){
  $('#page2-link').on('click',function(){
       $('#page').html( $('#page').html() ); //this will replace html content
  });
});

这篇关于同时浏览当前页面preLOAD第二页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆