填充标题中的URL参数

Populate the URL params in title

本文关键字:URL 参数 标题 填充      更新时间:2023-09-26

我需要帮助在页面标题的url中填充参数。最好的方法是什么?

www.mydns.com/sometext1/sometext2

sometext1|sometext2

感谢

您想根据url更新页面的标题吗?

document.title = window.location.pathname.split("/").slice(1).join(" | ");
  1. window.location.pathname为您提供{{/sometext1/sometext2}}
  2. 分开会把它分开
  3. 切片(1)将截断空索引
  4. join会把它重新组合起来

如果你想在PHP 中实现这一点

<title>My Page<?php echo str_replace('/',' | ',substr($_SERVER['REQUEST_URI'],1)); ?></title>