0
此腳本創建取決於表單數據的cookie,(例如:DOCNAME =我的文檔)割去表單數據
<script type="text/javascript">
{
var docname = getValue("docname"); // these go off another script to get form data
var save = getValue("save");
var url = window.location.href;
}
function setCookie(name, value, days) {
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
var expires = "; expires=" + date.toGMTString();
}
else var expires = "";
document.cookie = name + "=" + value + expires + "; path=/";
}
function saveDoc() {
if (docname != '') {
setCookie(docname,url,730);
}
else {
// Nothing else to do
}
}
// Helps to find errors if they exist
window.onerror = function(errorMessage, url, line) {
var errorText = 'message: ' + errorMessage + '\nurl: ' + url + '\nline: ' + line + ' please contact us, and report this error.';
alert(errorText);
}
</script>
它創建的cookie,並設置它的名字作爲docname變量,但是當它將url設置爲值時,它會切斷表單數據。
我已經研究並更改了代碼,但找不到答案,任何人都可以幫忙嗎?
解
<script type="text/javascript">
{
var docname = getValue("docname"); // these go off another script to get form data
var save = getValue("save");
var url = window.location.href;
var recode = encodeURIComponent(url);
}
function setCookie(name, value, days) {
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
var expires = "; expires=" + date.toGMTString();
}
else var expires = "";
document.cookie = name + "=" + value + expires + "; path=/";
}
function saveDoc() {
if (docname != '') {
setCookie(docname,recode,730);
}
else {
// Nothing else to do
}
}
// Helps to find errors if they exist
window.onerror = function(errorMessage, url, line) {
var errorText = 'message: ' + errorMessage + '\nurl: ' + url + '\nline: ' + line + ' please contact us, and report this error.';
alert(errorText);
}
</script>
改變用於將值設置爲recode
並設置重新編碼等於encodeURIComponent(url);
所以解碼url
變量,對其進行解碼並且使得能夠具有在值形式的數據或一個cookie等感謝的名義@epascarello
我可以這樣使用:'encodeURIComponent(window.location.href)'導致它仍然使用new-doc.html?docname創建cookie,而不是new-doc.html?docname = My Document&value = somthing等。@epascarello – internetgho5t 2013-05-09 19:21:09
它現在的作品非常感謝您的幫助! @epascarello – internetgho5t 2013-05-09 19:26:25