最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Changing document title is not working - Stack Overflow

programmeradmin2浏览0评论

I'm trying to add the notification number to the title in a function, but it won't work. This is my code:

  var docTitle = document.title;

  document.title = "".docTitle." (".$(".loadnot").html().")";

I'm trying to add the notification number to the title in a function, but it won't work. This is my code:

  var docTitle = document.title;

  document.title = "".docTitle." (".$(".loadnot").html().")";
Share Improve this question asked Oct 13, 2012 at 14:50 impimp 4702 gold badges7 silver badges23 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 9

In JavaScript you should use + for concatenating not ..

document.title = docTitle + "(" + $(".loadnot").html() + ")";

Or even better:

document.title += " ("+$(".loadnot").html()+")";

If none of the answers above fit then is simply:

Some Javascript server side is blocking the changing of the document title.

Check how -> https://stackoverflow./a/27847787/16759195

All you have to do is to add to your code the following lines:

Object.defineProperty(document, 'title', {
  enumerable: true,
  configurable: true,
  writable: true,
  value: document.title
});

check this:

window.top.document.title = "Your Title";
发布评论

评论列表(0)

  1. 暂无评论