document.title中压缩了播放符号(▶) [英] Play symbol (▶) squished in document.title

查看:110
本文介绍了document.title中压缩了播放符号(▶)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

>为什么要做▶的HTML符号在document.title中不起作用, 当我使用正确转义的javascript十六进制值将播放符号添加到文档标题时,该符号似乎被压缩了:

Adding to the question on Why does the HTML symbol for ▶ not work in document.title, when I add the play symbol to the document title using the properly escaped javascript hex value, the symbol seems squished:

JavaScript:

document.title = '\u25BA' + document.title;

内页 (正确)

内部标题 (不太正确)

有关此工作模型,请参见此小提琴.我添加了 /show/light ,以便javascript可以实际访问主页上的文档标题,但是如果您删除扩展名,则也可以看到代码.

See this fiddle for a working model. I've added /show/light so the javascript can actually access the document title on the main page, but if you take off the extension, you can see the code as well.

这似乎发生在所有主流浏览器(Chrome,Firefox,IE)上.

This appears to be happening on all major browsers (Chrome, Firefox, IE).

经过测试(在Win8上):

  • Chrome浏览器:版本30.0
  • Firefox:版本22.0
  • IE:版本10.0
  • Chrome: version 30.0
  • Firefox: version 22.0
  • IE: version 10.0

当我访问YouTube时,它看起来还不错,所以我不认为这是特定于浏览器的问题.

When I go to YouTube, it looks fine, so I'm not positive it's a Browser Specific Issue.

推荐答案

通过将YouTube使用的符号(▶)粘贴到代码点中. net ,您会看到它们实际上使用的是其他unicode版本.返回的字符为 U+25B6 (请勿与25B8混淆)和25BA)

By Pasting the symbol that YouTube uses (▶) into codepoints.net, you can see that they are actually using a different unicode version. The character returned is U+25B6 (not to be confused with 25B8 and 25BA)

应该看起来更好:

function PrependPageTitle(player) {
    var playIcon = '\u25B6 ';
    var startsWithIcon = document.title.substring(0, playIcon.length)===playIcon;

    if (player.paused && startsWithIcon) {
        document.title = document.title.slice(playIcon.length);
    } else if (!player.paused && !startsWithIcon) {
        document.title = playIcon + document.title;
    }
}

此处演示:

这篇关于document.title中压缩了播放符号(▶)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆