好的,情况就是这样。
我在页面中嵌入了一个语言切换链接,它将 URL 的字符串从 -eng.shtml 更改为 -fra.shtml 以及 Alias 值。
现在基本上在标题中我调用了两个脚本:
<script type="text/javascript" src="/js/langDB.js"></script>
<script type="text/javascript" src="/js/langToggle.js"></script>
LangToggle.js 在 langDB.js 中有一个函数,但是当调用编程到 langDB.js 中的函数时,它并没有按预期工作,它的功能应该是将变量值从一个更改为另一个。
切换代码:
function js_changeit(){
//Get the current page full URL
var mainName = String(window.location);
//Base name
var slash = mainName.lastIndexOf("/");
var dot = mainName.lastIndexOf(".");
var quest = mainName.lastIndexOf("?");
var name = mainName.substring(slash+1,dot);
var ext = mainName.substring(dot,mainName.length);
//Remove the _f is it exists
var lang = name.substring(name.length-3,name.length);
//Detect the site sections, get the current site title and the site primary alias strings
var SiteSection = mainName.split("/");
var currentAlias = SiteSection[3];
var currentSite = SiteSection[2];
//Split the url from Site to the end Alias section
var siteSectionAlias = "http://" + currentSite + "/" + currentAlias + "/";
var SectionaAlias = mainName.split(siteSectionAlias)
var htmlFullDocFilename = SectionaAlias[1];
//Extract the filename without the extension
var shtmlLastPos = htmlFullDocFilename.lastIndexOf(".shtml");
var docTitle = htmlFullDocFilename.substring(0,shtmlLastPos-4);
//Alias Toggles, when an alias is detected in the conditional list, switch to the other.
langToggle();
// Main Page
if (lang != "eng") {
window.open("http://" + currentSite + "/" + currentAlias + "/" + docTitle + "-eng" + ext, "_self");
} else {
window.open("http://" + currentSite + "/" + currentAlias + "/" + docTitle + "-fra" + ext, "_self");
}
}
langDB.js 中的函数:
function langToggle() {
switch(currentAlias) {
//Switch the variable from English to French and vice versa depending on the current page's URL string when the toggle js link is clicked
//If ENGLISH switch the variable to French
case "about-us":
currentAlias = "a-notre-sujet"; break;
//If FRENCH switch the variable to French
case "a-notre-sujet":
currentAlias = "about-us"; break;
/* -------------------------------------[ See the first two comments ]---------------------------------- */
case "facilities-and-security":
currentAlias = "installations-et-securite"; break;
case "installations-et-securite":
currentAlias = "facilities-and-security"; break;
/* -------------------------------------[ See the first two comments ]---------------------------------- */
case "offenders":
currentAlias = "delinquants"; break;
case "delinquants":
currentAlias = "offenders"; break;
/* -------------------------------------[ See the first two comments ]---------------------------------- */
case "you-and-csc":
currentAlias = "scc-et-vous"; break;
case "scc-et-vous":
currentAlias = "you-and-csc"; break;
/* -------------------------------------[ See the first two comments ]---------------------------------- */
case "connecting":
currentAlias = "etablir-des-liens"; break;
case "etablir-des-liens":
currentAlias = "connecting"; break;
/* -------------------------------------[ See the first two comments ]---------------------------------- */
case "resources":
currentAlias = "ressources"; break;
case "ressources":
currentAlias = "resources"; break;
/* -------------------------------------[ See the first two comments ]---------------------------------- */
case "international-transfers":
currentAlias = "transferements-internationaux"; break;
case "transferements-internationaux":
currentAlias = "international-transfers"; break;
/* -------------------------------------[ See the first two comments ]---------------------------------- */
case "educational-resources":
currentAlias = "ressources-pedagogiques"; break;
case "ressources-pedagogiques":
currentAlias = "educational-resources"; break;
/* -------------------------------------[ See the first two comments ]---------------------------------- */
case "cfp":
currentAlias = "pfc"; break;
case "pfc":
currentAlias = "cfp"; break;
}
}
当我单击语言切换链接时,IE 会给我一个“currentAlias”未定义的错误,基本上变量的值似乎没有加载到从外部脚本调用的函数中......
我不太确定我做错了什么......