DevStud DevStud - 3 years ago 183
CSS Question

Safari ReferenceError: Can't find variable: Set

I am getting Safari

ReferenceError: Can't find variable: Set
error from safari browser. I have checked other browsers but I didn't get any this error all codes working fine for me.

Is anyone can help me here what is wrong here and what is the solution to work my code from all browsers?

Full Demo

Problem Line

var charactersX = new Set([
0,
32, // space
13 // enter
// add other punctuation symbols or keys
]);
// Convert characters to charCode
function toCharCodeX(char) {
return char.charCodeAt(0);
}

var forbiddenCharactersX = new Set([
toCharCodeX("_"),
toCharCodeX("-"),
toCharCodeX("?"),
toCharCodeX("*"),
toCharCodeX("\\"),
toCharCodeX("/"),
toCharCodeX("("),
toCharCodeX(")"),
toCharCodeX("="),
toCharCodeX("&"),
toCharCodeX("%"),
toCharCodeX("+"),
toCharCodeX("^"),
toCharCodeX("#"),
toCharCodeX("'"),
toCharCodeX("<"),
toCharCodeX("|"),
toCharCodeX(">"),
toCharCodeX("."),
toCharCodeX(","),
toCharCodeX(";")
]);

Answer Source

Use arrays instead

var charactersX = [
  0,
  32, // space
  13 // enter
  // add other punctuation symbols or keys
];

and replace the .has(), e.g. here:

if (charactersX.has(code))

with

if (charactersX.indexOf(code) > -1) 

and

if (forbiddenCharactersX.has(code))

with indexOf > -1 too...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download