elliott.david 2016-02-18 11:23 采纳率: 25%
浏览 104

用js更改页面标题

I'm using some Ajax/other code (from https://jesse.sh/rethinks-dynamic-page-replacing-content/) to load partial page content into a specific div.

As it doesn't grab the title of the new content, the page title unhelpfully remains that of the initially-loaded page.

Unable to find a solution which handles the title appropriately, I'm using a kludge of 'console.log(href);' with 'document.title = location.href.replace ()' to produce an url-based title, from which are then removed the http:// and various other things before the page title.

It seems to work, but requires me to think about just what needs to be removed and chain accordingly.

In the absence of some code which replaces the title accordingly and thus doesn't require the above kludge, I'd like to be able to use a single unchained 'replace' which removes everything before the page title.

However, I don't understand enough to be able to do so.

Suggestions appreciated - please/thanks/etcetera.

  • 写回答

1条回答 默认 最新

  • 斗士狗 2016-02-18 11:25
    关注

    Use document.title. For example

    document.title='your title';
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分