jScript debugger error, in simple script

2020-03-31 04:13发布

问题:

I'm working on a local html file, stored on a Win7 machine and opened in IE 9. This html file uses javascript and jStorage.

However, when I run, I get the error "SCRIPT5007: Unable to get value of the property 'set': object is null or undefined." This error points to the statement $.jStorage.set("Key", "Hello");.

What am I doing wrong? I've made the html and javascript about as basic as I can, to narrow things down.

Here's the html:

<!DOCTYPE html>
<html>
    <head>
    <title>Backlog Tracker</title>
    <script src="jquery-2.1.1.min.js"></script>
    <script src="json2.js"></script>
    <script src="jstorage.min.js"></script>
    <script src="backlog.js"></script>
    </head>
    <body>
    </body>
</html>

... and, here's the script (referenced as "backlog.js" in the html):

$(document).ready(function(){
    $("body").append("<button>Try It</button>");
    $("button").click(function(){
    $.jStorage.set("Key", "Hello");
    console.log($.jStorage.get("Key"));
    });
});

As a side note, I've read other questions on SO, such as here, but nothing seems to explain this. Reference jStorage usage here, everything seems to be in order. I was originally pointed to jStorage thanks to this SO answer.

回答1:

localStorage does not work for local files in IE. It does in Chrome but not in IE.

Also IE 9 does support JSON if you have <!DOCTYPE html> and <meta http-equiv="X-UA-Compatible" content="IE=edge;chrome=1" /> in your document.

Try to run a small local web server.