有谁知道如何在 Coldfusion 中进行类似于 JavaScript 中的重定向的重定向?我在 javascript 方面遇到的问题是人们只是关闭 javascript。另外是否可以写一些东西来强制他们保持 javascript 开启或让他们下载它(如果他们没有)?
<script language="javascript">
function SelectRedirect(){
// ON selection of section this function will work
//alert( document.getElementById('pcount').value);
switch(document.getElementById('pcount').value)
{
case "0":
alert('Please select number of owners.');
window.location="";
break;
case "1":
window.location="One/ownerInfo1.cfm";
break;
case "2":
window.location="Two/ownerInfo2.cfm";
break;
case "3":
window.location="Three/ownerInfo3.cfm";
break;
case "4":
window.location="Four/ownerInfo4.cfm";
break;
case "5":
window.location="Five/ownerInfo5.cfm";
break;
}// end of switch
}
//////////////////
</script>
</head>
<h3>How many owners are taking title?
<SELECT id="pcount" NAME="pcount">
<Option value="0">Select Section</option>
<Option value="1">1</option>
<Option value="2">2</option>
<Option value="3">3</option>
<Option value="4">4</option>
<Option value="5">5</option>
</SELECT></h3>
<input type="submit" name="Submit" value="Next" onClick="SelectRedirect();">
最佳答案
Also is it possible to write something to force them to either keep javascript on or make them download it if they do not have it?
不,这是不可能的,您唯一能做的就是在未检测到 JS 的情况下阻止输出,并在 <noscript>
中通知您的访问者。阻止,但我认为这是非常糟糕的做法。以一种可以同时使用 JS 和关闭 JS 的方式构建您的应用程序。
话虽这么说,你应该从无 JS 版本开始,不显眼地添加 JS 功能。例如。包裹<select>
和<input type="submit">
在 <form>
其中action
目标是服务器端操作,然后才添加 JS 作为性能增强器,但永远不要单独依赖 JS。
快速代码示例:
<cfif structKeyExists(url, 'pickPage') and structKeyExists(form, 'pcount')>
<cfswitch expression=#form.pcount#>
<cfcase value="0">
<cfoutput>Error</cfoutput>
</cfcase>
<cfcase value="1">
<cflocation url="One/ownerInfo1.cfm">
</cfcase>
</cfswitch>
</cfif>
<form action="?pickPage" method="post">
<SELECT id="pcount" NAME="pcount">
<Option value="0">Select Section</option>
<Option value="1">1</option>
</SELECT>
<input type="submit" name="Submit" value="Next" onclick="SelectedRedirect(); return false;">
</form>
<script type="text/javascript">
function SelectRedirect() {
switch (document.getElementById('pcount').value) {
case "0":
alert('Please select number of owners.');
window.location = "";
break;
case "1":
window.location = "One/ownerInfo1.cfm";
break;
}
}
</script>
关于javascript - Coldfusion 中的重定向——还是强制 Javascript?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26121129/