嗨,我有一个单页ajax网站的单页基本上是加载所有的页面,我想设置根据当前视图的页面标题。
我试过使用这个
<title><!--TITLE--></title>
<?
$pageContents = ob_get_contents (); // Get all the page's HTML into a string
ob_end_clean (); // Wipe the buffer
// Replace <!--TITLE--> with $pageTitle variable contents, and print the HTML
echo str_replace ('<!--TITLE-->', $pageTitle, $pageContents);
?>
然后我将标题添加到页面链接中,像这样
<li class="menu-link">
<a href="index.php?page=home"><img src="images/menu/home.png" width="72" height="72" alt="Home" />Home</a>
<?php $pageTitle = 'Saunders-Solutions Freelance Design and Development'; ?>
</li>
<li class="menu-link">
<a href="index.php?page=about"><img src="images/menu/about.png" width="72" height="72" alt="About" />About</a>
<?php $pageTitle = 'About Saunders-Solutions Freelance Design and Development'; ?>
</li>
但是它总是在所有页面显示相同的标题,欢迎帮助
in javascript:
document.title = "New Title";
变量$pageTitle似乎是在str_replace替换之后定义的。也许你可以发布更多的代码来看看问题是什么
你可以直接打印HTML吗?
print "<TITLE>".$pageTitle."</TITLE>";
然后删除其他设置标题的代码:
,
<title><!--TITLE--></title>
<?
$TITLE[home]="Saunders-Solutions Freelance Design and Development";
$TITLE[about]="About Saunders-Solutions Freelance Design and Development";
?>
<title><?=$TITLE[$_GET[page]]?></title>
<li class="menu-link">
<a href="index.php?page=home"><img src="images/menu/home.png" width="72" height="72" alt="Home" />Home</a>
</li>
<li class="menu-link">
<a href="index.php?page=about"><img src="images/menu/about.png" width="72" height="72" alt="About" />About</a>
</li>