Skip to main content

From the picture I assume that you wannawant to have (9) Title or (99) Title or (99+) foras notification indicator.

Here is the clean code that I am using.

Works in vanilla jsVanilla JS, jqueryjQuery, reactjsReactJS, angularjsAngularJS (not tested) and most probably any jsJavaScript framework or library

filterDocumentTitle = () => document.title.replace(/^\((\d+|\d+\+)\)/gm, '').trim()

Usage

if(notification > 0) {
    document.title = `(${notification}) ${filterDocumentTitle()}`
} else {
    document.title = filterDocumentTitle()
}

Jquery

$.ajax({
  url: '/api/notification-check',
  method: 'POST',
  success: function(notification) {
    if(notification > 0) {
        document.title = `(${notification}) ${filterDocumentTitle()}`
    } else {
        document.title = filterDocumentTitle()
    }
  }
});

Axios

axiso.post('/api/notification-check').then(({ data }) => {
  if(data.notification > 0) {
    document.title = `(${data.notification}) ${filterDocumentTitle()}`
  } else {
    document.title = filterDocumentTitle()
  }
})

The filterDocumentTitle function removes everything that matchmatches the above examples as notification indicator.

From the picture I assume that you wanna have (9) Title or (99) Title or (99+) for notification indicator

Here is the clean code that I am using.

Works in vanilla js, jquery, reactjs, angularjs (not tested) most probably any js framework or library

filterDocumentTitle = () => document.title.replace(/^\((\d+|\d+\+)\)/gm, '').trim()

Usage

if(notification > 0) {
    document.title = `(${notification}) ${filterDocumentTitle()}`
} else {
    document.title = filterDocumentTitle()
}

Jquery

$.ajax({
  url: '/api/notification-check',
  method: 'POST',
  success: function(notification) {
    if(notification > 0) {
        document.title = `(${notification}) ${filterDocumentTitle()}`
    } else {
        document.title = filterDocumentTitle()
    }
  }
});

Axios

axiso.post('/api/notification-check').then(({ data }) => {
  if(data.notification > 0) {
    document.title = `(${data.notification}) ${filterDocumentTitle()}`
  } else {
    document.title = filterDocumentTitle()
  }
})

filterDocumentTitle function removes everything that match above examples as notification indicator.

From the picture I assume that you want to have (9) Title or (99) Title or (99+) as notification indicator.

Here is the clean code that I am using.

Works in Vanilla JS, jQuery, ReactJS, AngularJS (not tested) and most probably any JavaScript framework or library

filterDocumentTitle = () => document.title.replace(/^\((\d+|\d+\+)\)/gm, '').trim()

Usage

if(notification > 0) {
    document.title = `(${notification}) ${filterDocumentTitle()}`
} else {
    document.title = filterDocumentTitle()
}

Jquery

$.ajax({
  url: '/api/notification-check',
  method: 'POST',
  success: function(notification) {
    if(notification > 0) {
        document.title = `(${notification}) ${filterDocumentTitle()}`
    } else {
        document.title = filterDocumentTitle()
    }
  }
});

Axios

axiso.post('/api/notification-check').then(({ data }) => {
  if(data.notification > 0) {
    document.title = `(${data.notification}) ${filterDocumentTitle()}`
  } else {
    document.title = filterDocumentTitle()
  }
})

The filterDocumentTitle function removes everything that matches the above examples as notification indicator.

update regular expression
Source Link

From the picture I assume that you wanna have (9) Title or (99) Title or (99+) for notification indicator

Here is the clean code that I am using.

Works in vanilla js, jquery, reactjs, angularjs (not tested) most probably any js framework or library

filterDocumentTitle = () => document.title.replace(/\^\((\d+|\d+\+)\)/gm, '').trim()

Usage

if(notification > 0) {
    document.title = `(${notification}) ${filterDocumentTitle()}`
} else {
    document.title = filterDocumentTitle()
}

Jquery

$.ajax({
  url: '/api/notification-check',
  method: 'POST',
  success: function(notification) {
    if(notification > 0) {
        document.title = `(${notification}) ${filterDocumentTitle()}`
    } else {
        document.title = filterDocumentTitle()
    }
  }
});

Axios

axiso.post('/api/notification-check').then(({ data }) => {
  if(data.notification > 0) {
    document.title = `(${data.notification}) ${filterDocumentTitle()}`
  } else {
    document.title = filterDocumentTitle()
  }
})

filterDocumentTitle function removes everything that match above examples as notification indicator.

From the picture I assume that you wanna have (9) Title or (99) Title or (99+) for notification indicator

Here is the clean code that I am using.

Works in vanilla js, jquery, reactjs, angularjs (not tested) most probably any js framework or library

filterDocumentTitle = () => document.title.replace(/\((\d+|\d+\+)\)/gm, '').trim()

Usage

if(notification > 0) {
    document.title = `(${notification}) ${filterDocumentTitle()}`
} else {
    document.title = filterDocumentTitle()
}

Jquery

$.ajax({
  url: '/api/notification-check',
  method: 'POST',
  success: function(notification) {
    if(notification > 0) {
        document.title = `(${notification}) ${filterDocumentTitle()}`
    } else {
        document.title = filterDocumentTitle()
    }
  }
});

Axios

axiso.post('/api/notification-check').then(({ data }) => {
  if(data.notification > 0) {
    document.title = `(${data.notification}) ${filterDocumentTitle()}`
  } else {
    document.title = filterDocumentTitle()
  }
})

filterDocumentTitle function removes everything that match above examples as notification indicator.

From the picture I assume that you wanna have (9) Title or (99) Title or (99+) for notification indicator

Here is the clean code that I am using.

Works in vanilla js, jquery, reactjs, angularjs (not tested) most probably any js framework or library

filterDocumentTitle = () => document.title.replace(/^\((\d+|\d+\+)\)/gm, '').trim()

Usage

if(notification > 0) {
    document.title = `(${notification}) ${filterDocumentTitle()}`
} else {
    document.title = filterDocumentTitle()
}

Jquery

$.ajax({
  url: '/api/notification-check',
  method: 'POST',
  success: function(notification) {
    if(notification > 0) {
        document.title = `(${notification}) ${filterDocumentTitle()}`
    } else {
        document.title = filterDocumentTitle()
    }
  }
});

Axios

axiso.post('/api/notification-check').then(({ data }) => {
  if(data.notification > 0) {
    document.title = `(${data.notification}) ${filterDocumentTitle()}`
  } else {
    document.title = filterDocumentTitle()
  }
})

filterDocumentTitle function removes everything that match above examples as notification indicator.

clear documentation
Source Link

From the picture I assume that you wanna have (9) Title or (99) Title or (99+) for notification indicator

Here is the clean code that I am using.

Works in vanilla js, jquery, reactjs, angularjs (not tested) most probably any js framework or library

// works in vanilla js, jquery, reactjs, angularjs (not tested) most probably any js framework
filterDocumentTitle = () => document.title.replace(/\((\d+|\d+\+)\)/gm, '').trim()
 
// usage
// your ajax or socket query to api

Usage

if(notification > 0) {
    document.title = `(${notification}) ${filterDocumentTitle()}`
} else {
    document.title = filterDocumentTitle()
}

// Jquery e.g.

Jquery

$.ajax({
  url: '/api/notification-check',
  method: 'POST',
  success: function(notification) {
    if(notification > 0) {
        document.title = `(${notification}) ${filterDocumentTitle()}`
    } else {
        document.title = filterDocumentTitle()
    }
  }
});
 
// axios e.g.

Axios

axiso.post('/api/notification-check').then(({ data }) => {
  if(data.notification > 0) {
    document.title = `(${data.notification}) ${filterDocumentTitle()}`
  } else {
    document.title = filterDocumentTitle()
  }
})

filterDocumentTitle function removes everything that match above examples as notification indicator.

From the picture I assume that you wanna have (9) Title or (99) Title or (99+) for notification indicator

Here is the clean code that I am using.

// works in vanilla js, jquery, reactjs, angularjs (not tested) most probably any js framework
filterDocumentTitle = () => document.title.replace(/\((\d+|\d+\+)\)/gm, '').trim()
 
// usage
// your ajax or socket query to api
if(notification > 0) {
    document.title = `(${notification}) ${filterDocumentTitle()}`
} else {
    document.title = filterDocumentTitle()
}

// Jquery e.g.
$.ajax({
  url: '/api/notification-check',
  method: 'POST',
  success: function(notification) {
    if(notification > 0) {
        document.title = `(${notification}) ${filterDocumentTitle()}`
    } else {
        document.title = filterDocumentTitle()
    }
  }
});
 
// axios e.g.
axiso.post('/api/notification-check').then(({ data }) => {
  if(data.notification > 0) {
    document.title = `(${data.notification}) ${filterDocumentTitle()}`
  } else {
    document.title = filterDocumentTitle()
  }
})

filterDocumentTitle function removes everything that match above examples as notification indicator.

From the picture I assume that you wanna have (9) Title or (99) Title or (99+) for notification indicator

Here is the clean code that I am using.

Works in vanilla js, jquery, reactjs, angularjs (not tested) most probably any js framework or library

filterDocumentTitle = () => document.title.replace(/\((\d+|\d+\+)\)/gm, '').trim()

Usage

if(notification > 0) {
    document.title = `(${notification}) ${filterDocumentTitle()}`
} else {
    document.title = filterDocumentTitle()
}

Jquery

$.ajax({
  url: '/api/notification-check',
  method: 'POST',
  success: function(notification) {
    if(notification > 0) {
        document.title = `(${notification}) ${filterDocumentTitle()}`
    } else {
        document.title = filterDocumentTitle()
    }
  }
});

Axios

axiso.post('/api/notification-check').then(({ data }) => {
  if(data.notification > 0) {
    document.title = `(${data.notification}) ${filterDocumentTitle()}`
  } else {
    document.title = filterDocumentTitle()
  }
})

filterDocumentTitle function removes everything that match above examples as notification indicator.

added 647 characters in body
Source Link
Loading
Source Link
Loading