Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html lang="ko">
- <head>
- <meta charset="UTF-8">
- <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
- <title>local storage example</title>
- </head>
- <body>
- <form>
- <input type="text" name="search" id="search">
- </form>
- <script>
- var ls;
- var storage;
- if(typeof(Storage) !== "undefined") {
- ls = true;
- storage = window.localStorage;
- } else {
- ls = false;
- storage = null;
- }
- $(function(){
- $("#search").keyup(function() {
- if(ls){
- storage.setItem("searchText", $(this).val());
- }
- });
- });
- window.onload = function(){
- if(ls){
- var searchText = storage.getItem("searchText");
- $("#search").val(searchText);
- }
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment