我的网站有关于标题标签的问题<title></title>
。我想将它连接到数据库,以便我的网页标题的值来自数据库,它有效。但是当我想让我的网页标题(不是整个页面)自动刷新时发生了另一个问题。我从 ajax 找到了脚本,但它并没有像在 facebook 标题标签中那样真正成功,假设我从另一个浏览器(即 Opera 等)输入新数据,然后回到我的主浏览器(Firefox)标题标签根本不改变或不自动刷新和改变值。我真的需要你们的帮助......!?这是我试过的脚本..
setInterval(function() {
$.ajax({
url: '{BASE_URL}/system/back-end/main.php',
url: 'main.html',
//data: {name: 'username', password: 'userpass'},
success: function() { document.title = '$value';},
dataType: 'text'
});
}, 1000);
function getXHR() {
if (window.XMLHttpRequest) {
// Chrome, Firefox, IE7+, Opera, Safari
return new XMLHttpRequest();
}
// IE6
try {
// The latest stable version. It has the best security, performance,
// reliability, and W3C conformance. Ships with Vista, and available
// with other OS's via downloads and updates.
return new ActiveXObject('MSXML2.XMLHTTP.6.0');
} catch (e) {
try {
// The fallback.
return new ActiveXObject('MSXML2.XMLHTTP.3.0');
} catch (e) {
alert('This browser is not AJAX enabled.');
return null;
}
}
}
function setPageTitle(newValue) {
document.title = '$value';
}
function messageCountAsPageTitle(msgCount) {
// TODO: determine where 'another text in the page title' should be defined
msgCount = '{PESAN_ENTRY} {BERKAS} {BERKAS}';
setPageTitle('(' + msgCount + ') - another text in the page title');
}
<!--</tpl:tmpl>
function getMessageCount(callback) {
var url = 'main.html?' + 'main.php?' + (new Date()).getTime(), // prevent caching
xhr = getXHR();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
callback(xhr.responseText);
}
};
xhr.timeout = 2000; // Set the timeout to be less than the frequency we call this
xhr.open("GET", url, true);
xhr.send();
}
setInterval(function() {getMessageCount(messageCountAsPageTitle);}, 3000);
请帮忙?