0

I've tested a Javascript on JSFiddle for a localStorage-working textarea. Once I make the HTML page and load it up, it doesn't use the Javascript written.

Here's my HTML code:

<html>
<head>
<title>Page Title</title>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.4.2.js'></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.js"></script>
<script type='text/javascript'>
    jQuery(function($) {
    var editor = document.querySelector("#editor");
    if (window.localStorage["TextEditorData"]) {
        editor.value = window.localStorage["TextEditorData"];
    }    
    editor.addEventListener("keyup", function() {
    window.localStorage["TextEditorData"] = editor.value;
    });
</script>
</head>
<body onLoad=".ready()">
<textarea id="editor"></textarea>
</body>
</html>

What did I miss? Testing it on JSFiddle works correctly.

  • 1
    Are you using a webserver, or just are you just double-clicking the file? – Daedalus Mar 03 '13 at 08:43
  • 4
    `onLoad=".ready()"` is a syntax error in JS. Might or might not be related to the problem. – Felix Kling Mar 03 '13 at 08:45
  • What I don't get here, is where the ready() function comes from? Its no where declared in your code snippet in your question. Please format your code better, before you post it here. – Uwe Günther Mar 03 '13 at 09:13
  • Check jsFiddle FAQ http://doc.jsfiddle.net/faq.html#code-is-working-on-jsfiddle-not-on-site-local-machine – zalun Mar 03 '13 at 13:28

1 Answers1

1

I've tested your code on a webserver that I installed on my local machine. A few tests revealed what appeared to be the cause of your woes.. A missing pair of closing brackets:

});

This closes your jQuery(function($) { call above, and your code then works fine for me. Of course, I also removed that errant onload=".ready()" call.

Daedalus
  • 7,586
  • 5
  • 36
  • 61