I am developing a web application and am using the jqTree plugin for a tree menu. I'm using the saveState argument when creating the tree. It works fine in FireFox 12 i.e. it remembers the state of the tree on a refresh (uses localStorage) but in Internet Explorer 11 it is not saving the data to either localStorage or as a cookie (I've added the JQuery cookie as per the instructions from the author of jqTree, and I can read and write cookies fine).
Out of desperation, I saved a list of open nodes into localStorage as a string, and then tried to loop through the list and use the openNode function of jqTree to open the nodes. This did not work either. Can anyone please advise any workaround/fix? Thank you very much. :)
P.S. It is crashing in IE11 with the error message "'JSON' is undefined" on line 1839 of tree.jquery.js.
Update: The above error was fixed by adding js_json2.js to the configuration and changing line 1839 of tree.jquery.js to
state = JSON.stringify(this.getState(),undefined); //added undefined as second argument
However now the nodes that are collapsed show the expand/collapse icon correctly, but the child nodes that should be invisible are still displayed as below :
▼node1ajax
child1 child2
▼node2
child3
►child4
sub2
In this case, sub2 should not be visible but is.
The error message
JSON is undefined
is an important clue here.The
JSON
API is a standardised API that is supported by all current browsers, including IE11 and Firefox (yes, even as far back as FF12).So why would IE11 say that it's undefined when it supports it?
There is only one possible reason for this: IE must be in a backward compatibility mode that removes support for the JSON API.
There are two possible modes that this could be: Either IE7 compatibility mode or Quirks mode. The solution depends on which mode you're in.
You can find out which one you're in by hitting F12 to bring up the browser dev tools, and going to the Emulation tab. If the number it shows is "7" then you're in IE7 mode, if it's 5 then you're in quirks mode.
Quirks mode: All versions of IE will fall back into quirks mode if your HTML code doesn't have a valid doctype. You can also trigger it with certain types of invalid HTML, but the missing doctype is by far the most common reason.
So make sure your HTML pages all begin with a line that looks like this:
<!DOCTYPE html>
. That should make sure you're not in quirks mode. (other valid doctypes are fine as well, but that's the easiest one to go with).Also, run your HTML through the W3C validator to make sure that you don't have any broken HTML that could affect it as well.
IE7 Compatibility mode: This is often triggered by browser settings, especially in corporate network environments. You can override it by specifying the
X-UA-Compatible
meta tag. You can do this by adding the following line to the<head>
section of your HTML code:Do both of the above things and the browser should go into standards mode, which should mean you find that IE11 starts behaving itself a whole lot better. You won't need to add js_json2.js any more, and you can probably undo all the other 'fixes' you've made to try to resolve it.
Hope that helps.