Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
100
rated 0 times [  107] [ 7]  / answers: 1 / hits: 29206  / 9 Years ago, tue, august 18, 2015, 12:00:00

I am banging my head trying to find the error in this code. I have checked it so many times can someone point out where the problem is?



$(function() {
try {
function endswith(str, ends) {
if (ends === '') return true;
if (str == null || ends == null) return false;
str = String(str);
ends = String(ends);
return str.length >= ends.length && str.slice(str.length - ends.length) === ends;
}
var referrer = new URL(document.referrer).domain;
if (endswith(referrer, xyz.com)) {
$(.logo .logo-external).remove();
} else {
$(.logo .logo-internal).remove();
}
} catch () {}
});

More From » try-catch

 Answers
3

catch (e) {} You missed the variable e



$(function() {
try {
function endswith(str, ends) {
if (ends === '') return true;
if (str == null || ends == null) return false;
str = String(str);
ends = String(ends);
return str.length >= ends.length && str.slice(str.length - ends.length) === ends;
}
var referrer = new URL(document.referrer).domain;
if (endswith(referrer, xyz.com)) {
$(.logo .logo-external).remove();
} else {
$(.logo .logo-internal).remove();
}
} catch (e) {}
});

[#65376] Sunday, August 16, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
collinisaaka

Total Points: 194
Total Questions: 105
Total Answers: 104

Location: Tonga
Member since Tue, Nov 30, 2021
3 Years ago
;