简体   繁体   English

Firefox xul浏览器没有页面标题

[英]Firefox xul browser doesn't have a page title

Firefox browser element does not return page title when tabs are loaded from previous session. 从上一个会话加载选项卡时,Firefox浏览器元素不会返回页面标题。 The code I use: 我使用的代码:

var browsers = gBrowser.browsers;
for (var i = 0, len = browsers.length; i < len; i++) {
    dump('page title #1: ' + browsers[i].contentTitle + '\n'); // here I get no title
    dump('page title #2: ' + browsers[i].contentDocument.title + '\n'); // nothing here
    dump('url: ' + browsers[i].contentDocument.location + '\n'); // url is fully loaded here 
}

So the question is: how do I get the page title? 所以问题是:如何获得页面标题? Pages start loading when I activate the tab. 当我激活标签页时,页面开始加载。 But page title is shown in the tab list right after the browser starts. 但是页面标题会在浏览器启动后立即显示在选项卡列表中。

The issue is that the pages are really not restored. 问题是页面实际上没有还原。 The tabs have about:blank loaded into them and the real page only starts loading when the user goes to the tab. 这些选项卡中已加载有about:blank ,只有当用户转到该选项卡时,实际页面才会开始加载。 So contentDocument.title cannot have any meaningful value. 因此contentDocument.title不能具有任何有意义的值。

What you apparently want is the title displayed on the tab - it doesn't reflect what is loaded into the tab, it's rather something remembered from the previous session. 您显然想要的是选项卡上显示的标题-它不反映选项卡中加载的内容,而是上一届会议上记住的内容。 So you should actually get the tab title, something like this: 因此,您实际上应该获得选项卡标题,如下所示:

var tabs = gBrowser.tabs;
for (var i = 0, len = tabs.length; i < len; i++) {
    dump('page title: ' + tabs[i].label + '\n');
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM