0

On a HTML page I use this javascript code to set cookies

this.store.setItem = function(name, value) {
    document.cookie = name + '=' + encodeURIComponent(value) + '; expires=' + expires;
};

I am trying to create a function that delete all cookies potentially set through the previous function. I found different threat about clearing cookies using javascript... This is an example of code that I have tested

deleteAllCokies : function() {
    var res = document.cookie;
    var multiple = res.split(";");
    for(var i = 0; i < multiple.length; i++) {
        var key = multiple[i].split("=");
        document.cookie = key[0]+" =; expires = Thu, 01 Jan 1970 00:00:00 UTC";
    }
}

The code works perfectly on computer running uptodated browsers. However when I try the code on older Browser( I runned the page as a webOS app) I get an error while trying to delete the cookies

SecurityError: DOM Exception 18: An attempt was made to break through the security policy of the user agent.

Someone has an idea about the problem?

Calvin Nunes
  • 6,376
  • 4
  • 20
  • 48
mbf
  • 1
  • Possible duplicate of [Javascript SecurityError: DOM Exception 18 while accessing cookies](https://stackoverflow.com/questions/27589092/javascript-securityerror-dom-exception-18-while-accessing-cookies) – James Dec 05 '18 at 17:13

2 Answers2

0

The other browser may have other cookies created by other sources that your script doesn't have permission to delete. Try to dump all the cookies in the console.log to verify this.

Enrico Dias
  • 1,417
  • 9
  • 21
0

I've saw this error in webos 1.x and 2.x. If your application is stored locally (built-in the ipk) the protocol to access the document is forced file:// by the OS. You can check this thread

LG recommends to use webStorage or serve your app by a webserver

PS: A hosted web app will use the HTTP/HTTPS protocol to access the document

stuckatzero
  • 699
  • 3
  • 8