阻止jQuery mobile设置document.title?

Ste*_*all 15 html javascript jquery jquery-mobile

它看起来像jQuery移动设置document.title到文本内容data-role="header",例如:

<div data-position="fixed" data-role="header">
    <h1>This text</h1>
</div>
Run Code Online (Sandbox Code Playgroud)

我有一个黑客解决方法来防止这样做:

$('div[data-role="page"]').bind('pageshow',function(){document.title = "My title"});

是否有更好/更具语义的方法来做到这一点?

Sta*_*ski 21

另一种解决方案是将原始文档标题复制到每个页面的data-title属性:

$(":jqmData(role='page')").attr("data-title", document.title);
Run Code Online (Sandbox Code Playgroud)

这种方法优于在页面显示上更改标题的优点是它可以防止页面转换期间文档标题闪烁.


Tro*_*ike 5

如果将值包装在div周围,则不会更新标题。像这样:

<div data-position="fixed" data-role="header">
    <div><h1>This text</h1></div>
</div>
Run Code Online (Sandbox Code Playgroud)