Hey i can't figure out why my code is not working. I've pulled out my hair please take a look and tell me what's wrong with this code
Note : it's working fine in chrome and mozilla only not working in IE10 and all below versions of IE
please note that am trying by two different ways so please don't confuse in that here is fiddle link http://jsfiddle.net/rEmn6/
here is my html code
<div id="wrapper">
<div id="editable" contenteditable="true" onkeyup="SaveValue(this)"></div>
<button onclick="clearData()" id="reset">Reset</button>
<br>
<textarea id="message" onKeyUp="setVal(this)"></textarea>
</div>
here is javascript code
var editable = document.getElementById('editable');
var store = window["localStorage"], storage = window.localStorage;
if (navigator.appVersion.indexOf("MSIE 7.") != 1){
console.log(navigator);
var msg = document.getElementById('message');
function setVal(ths) {
console.log(ths.value);
storage.setItem('sms', ths.value);
};
if(storage.getItem('sms')){
msg.value = storage.getItem('sms');
}
}
function SaveValue(ths){
var val = ths.innerHTML;
if (val != ''){
store.setItem('contenteditable', val)
console.log(val);
}
}
function clearData(){
console.log('clear hoga');
store.clear();
}
if (store.getItem('contenteditable')) {
editable.innerHTML = store.getItem('contenteditable');
}
If you are trying localStorage
on a local machine and without use of a web server like WAMP
, XAMPP
or similar programs. IE browser will definitely throws an error. So make sure that you are trying it in a web server for development purposes.
When you run your page from local filesystem, the browser will not act like he does for web server.