利用HTML5的本地存储制作的个性化导航页
2016-10-18 12:42
921 查看
本人做了一个HTML5页面,用于管理自己经常访问的网站。
数据使用HTML5的localStorage存储。下面是完整的页面代码。
页面的运行效果如下图所示。
数据使用HTML5的localStorage存储。下面是完整的页面代码。
<!DOCTYPE HTML> <html> <head> <style type="text/css"> a{margin:15px;font-size:28px;} </style> <script type="text/javascript"> function pageLoad() { for(var i=0; i<localStorage.length; i++) { var strKey = localStorage.key(i); var strValue = localStorage.getItem(strKey); addLink(strValue,strKey) } } function clickButton() { var navcContent = document.getElementById('navcContent'); var inputUrl = document.getElementById('inputUrl').value; var inputTips = document.getElementById('inputTips').value; addLink(inputUrl,inputTips) window.localStorage.setItem(inputTips,inputUrl) } function addLink(url,tips) { var fdStart = url.indexOf("http://"); var fdsStart = url.indexOf("https://"); if(fdStart == -1 && fdsStart==-1) { url ="http://" + url } var navcContent = document.getElementById('navcContent'); var href = document.createElement("a"); href.setAttribute("href", url); href.setAttribute("target", "_blank"); href.innerHTML = tips; navcContent.appendChild(href); } </script> <link rel="shortcut icon" href="myicon.ico"> </head> <body onLoad="pageLoad();"> <h1>My Navigate Page!!!!!</h1> <p>链接:<input type="text" id="inputUrl" style="width:250px"/> 名称:<input type="text" id="inputTips"/> <input type="button" value="新增" onclick="clickButton();"></p> <div id="navcContent"> <a href="http://fanyi.baidu.com/translate?aldtype=16047&query=&keyfrom=baidu&smartresult=dict&lang=auto2zh#auto/zh/" target="_blank">百度翻译</a> <a href="http://www.entts.com/" target="_blank">英文朗读</a> <a href="https://git.oschina.net/login" target="_blank">码云</a> <a href="http://www.erlang.org/downloads" target="_blank">erlang</a> <a href="http://www.w3school.com.cn/index.html" target="_blank">w3school</a> </div> </body> </html>
页面的运行效果如下图所示。
相关文章推荐
- 利用html5的本地存储功能实现登录用户信息保存
- HTML5本地储存追加利用html5的本地存储功能实现登录用户信息保存
- 利用HTML5开发Android(4)---HTML5本地存储之Web Storage
- 利用html5的本地存储写的一个购物车
- 利用HTML5开发Android(7)---HTML5本地存储之Database Storage
- 利用html5的本地存储功能实现登录用户信息保存
- js 通过post方式打开页面 利用html5本地存储获取数据
- HTML5本地存储(Local Storage) 的前世今生(二)
- HTML5 LocalStorage 本地存储
- html5本地存储在手机web app中使用探讨
- HTML5 localstorage本地存储应用
- HTML5本地存储(Local Storage) 的前世今生(二)
- HTML5 本地存储和内容按需加载的思路和方法
- 深入HTML5: HTML5 本地存储( Local Storage )的前世今生
- HTML5 localStorage本地存储实际应用举例(转)
- html5本地存储localStorage实战(1)(转)
- HTML5 本地存储DEMO ---localStorage
- html5的本地存储localstorage和web databases
- HTML5本地存储(Local Storage) 的前世今生(二)
- HTML5 本地存储 LocalStorage