Last active
August 29, 2015 13:59
-
-
Save gindis/10956435 to your computer and use it in GitHub Desktop.
记录上一次浏览页面位置
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| !function (){ | |
| 'use strict'; | |
| if (localStorage) { | |
| var docEle, | |
| w = window, | |
| d = document, | |
| l = localStorage, | |
| t = location.href, | |
| browserName=navigator.userAgent.toLowerCase(); | |
| //兼容IE | |
| if ((/chrome/i.test(browserName) && /webkit/i.test(browserName) && /mozilla/i.test(browserName))||(/webkit/i.test(browserName))) { | |
| docEle = d.body | |
| }else { | |
| docEle = d.documentElement ? d.documentElement : d.body; | |
| } | |
| //初始上一次浏览位置 | |
| docEle.scrollTop = l.getItem(t); | |
| w.onscroll = function () { | |
| //记录当前位置 | |
| l.setItem(t, docEle.scrollTop); | |
| } | |
| } | |
| }(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment