我一直在研究一些 JavaScript,到目前为止,最令人沮丧的事情之一是,如果使用 Back、Forward 或 Hard Refresh,我的 JavaScript 似乎拒绝加载。考虑到我的网站是建立在通过 MySQL 数据库连接重复生成的静态 HTML 页面上,我不得不手动添加一个版主菜单,但它似乎有时只是拒绝出现?
if (getCookie('opt23') !== '1') {
var ajaxtwo = new XMLHttpRequest();
var wrap = '';
if (document.getElementById("firstpage") !== null) {
wrap = document.getElementById("firstpage");
} else {
wrap = document.getElementById("firstpageinside");
}
var main = document.createElement("div");
main.setAttribute("id","modmenu");
wrap.appendChild(main);
ajaxtwo.onreadystatechange = function() {
var reports = (ajaxtwo.responseText === '0' ? 'flagblue.png' : 'flag.png');
reportcount.innerHTML = '<img src=' + ku_cgipath + '/css/images/mods/' + reports + ' style="height:15px;' +
'width:15px;" />' + ajaxtwo.responseText;
};
ajaxtwo.open("GET",ku_cgipath + "/manage_page.php?action=reports&count",true);
ajaxtwo.send();
var threadid = document.getElementsByName("replythread");
// taking the initiative of togglePassword, this makes things less needlessly lengthy.
main.innerHTML =
'<h2>Quick Mod</h2>' +
'<input type="hidden" name="threadid" value="' + threadid[0].value +'" />' +
'<label for="modaction">Action </label><select id="action" name="modaction">' +
'<option value=""><none></option>' +
'<option value="delpost">Delete posts</option>' +
'<option value="rebuildone">Rebuild board</option>' +
'<option value="bans">View Bans</option>' +
'<option value="appeals">View Appeals</option>' +
'<option value="stickypost">Sticky Thread</option>' +
'<option value="unstickypost">Unsticky Thread</option>' +
'<option value=lockpost>Lock Thread</option>' +
'<option value="unlockpost">Unlock Thread</option>' +
'<option value="bump">Instant Bump</option>' +
'<option value="viewthread">Switch to Moderator View</option>' +
'</select>' +
'<input type="submit" name="submit" value="Submit">' +
'<a href="' + ku_cgipath + '/manage_page.php?action=reports" target="_blank">' +
'<span id="reportcount"></span></a> ';
}
我的第二个问题是在我用来尝试使这些 HTML 页面动态运行的另一个 JavaScript 中。我正在使用 AJAX 与 PHP 脚本进行交互,但是,当它返回页面时(基本上是获取下一页并用 CSS 将它绑在第一个页面旁边,创建一个“双视图”),我的 JavaScript 没有得到应用,例如时间设置或生成的链接。如何处理?我不能使用window.onload
,因为它只能使用一次 - 它正在另一个 JavaScript 中使用。我只是以某种方式修改 PHP 文件的结果吗?我正在使用正则表达式来抓取下一页,所以我实际上无法修改 PHP 中的结果...可以吗?
愿意向大多数解决方案让步,包括重写。