如何防止谷歌浏览器缓存我的输入,尤其是当用户点击后隐藏的? [英] How to prevent google chrome from caching my inputs, esp hidden ones when user click back?
问题描述
我有一个asp.net mvc应用程序,它有很多隐藏的输入来保持值和格式化他们的名字,以便我在稍后提交表单时可以使用Model绑定。
当用户提交表单并单击后退按钮时,我偶然发现一个奇怪的Chrome浏览器问题,我没有使用IE或Firefox,我发现Chrome浏览器也会保留我的隐藏输入值。
这个整块是通过javascript生成的,因此我相信chrome会缓存这个。
function addProductRow(productId,productName){
if(productName!=){
//使用guid确保该行从不重复
var guid = $ .Guid.New();
var temp = parseFloat($(。tboProductCount)。val());
//需要span来解决镀铬问题
var szHTML =< tr valign = \top \id = \productRow\>< td class = \productIdCol\>< input type = \hidden\id = productRegsID+ temp +\name = \productRegs [+ temp +] .productId \value = \+ productId +\/>
+< span id = \spanProdID+ temp +\name = \spanProdID + temp +\>+ productId +< / span>
+< / td>
// +< td>< input type = \\ \\text \id = \productRegName\name = \productRegs [+ temp +] .productName\value = \+ productName +\class = \ productRegName \size = \50 \readonly = \readonly \/>< / td>
+< td>< span id = \ productRegName\name = \productRegs [+ temp +] .productName\class = \productRegName\& < / productName +< \ span>< / td>
+< td id = \+ guid +\class = \productrowguid \ \
+< input type = \text \size = \20 \id = \productSerialNo+ temp +\name = \ productRegs [+ temp +] .serialNo\value = \+\class = \productSerialNo\maxlength = \18 \/>
+< a class = \fancybox \id = \btnImgSerialNo+ temp +\href = \#divSerialNo+ temp +\>< img class = \btnImgSerialNo\src = \Images / landing_14.gif\/>< / a>
+< span id = \snFlag+ temp + \class = \redWarning\>< / span>< / td>
+< td>< input type = \text \id = \\ \\productRegDate+ temp +\name = \productRegs [+ temp +] .PurchaseDate \readonly = \readonly \/>
+< span id = \snRegDate+ temp +\class = \redWarning\>< / span>< / td>
+< td align = \center \>< img style = \cursor:pointer \id = \btnImgDelete\src = \Images / btn_remove.gif\onclick = \\ \\javascript:removeProductRow('+ guid +')\/>< div style = \display:none; \>< div id = \divSerialNo+ temp + \style = \font-family:verdana; font-size:11px; width:600px \>+ serialnumbergeneral +< br />< br />+ getSNImageByCategory < / td>
+< / tr>;
$(。ProductRegistrationTable)。append(szHTML);
$(a.fancybox)。fancybox();
//初始化
$(#productRegDate+ temp).datepicker({
minDate:new Date(1996,1 - 1,1),
maxDate:0
});
//完整性检查
// s7test
alert('1'+ $(#spanProdID+ temp));
alert('2'+ $(#productRegsID+ temp));
} //结束函数addNewProductRow
我需要id在用户选择新产品时刷新,但在旁边放置另一个span标签显示跨度将具有新id,隐藏的输入仍将具有以前的id。
有没有一个优雅的方法来解决这个问题?
谢谢
我的老板找到了答案,这是一个简单的autocomplete =off添加到输入属性中,虽然vwd会将其标记为错误:)
i have an asp.net mvc app which have quite a few hidden inputs to keep values around and formatting their names so that i can use the Model binding later when i submit the form.
i stumble into a weird bug with chrome which i don't have with IE or Firefox when the user submits the form and click on the back button, i find that chrome will keep my hidden input values as well.
this whole chunk is generated via javascript hence i believe chrome is caching this.
function addProductRow(productId, productName) {
if (productName != "") {
//use guid to ensure that the row never repeats
var guid = $.Guid.New();
var temp = parseFloat($(".tboProductCount").val());
//need the span to workaround for chrome
var szHTML = "<tr valign=\"top\" id=\"productRow\"><td class=\"productIdCol\"><input type=\"hidden\" id=productRegsID" + temp + "\" name=\"productRegs[" + temp + "].productId\" value=\"" + productId + "\"/>"
+ "<span id=\"spanProdID" + temp + "\" name=\"spanProdID" + temp + "\" >" + productId + "</span>"
+ "</td>"
//+ "<td><input type=\"text\" id=\"productRegName\" name=\"productRegs[" + temp + "].productName\" value=\"" + productName + "\" class=\"productRegName\" size=\"50\" readonly=\"readonly\"/></td>"
+ "<td><span id=\"productRegName\" name=\"productRegs[" + temp + "].productName\" class=\"productRegName\">"+ productName + "<\span></td>"
+ "<td id=\"" + guid + "\" class=\"productrowguid\" \>"
+ "<input type=\"text\" size=\"20\" id=\"productSerialNo" + temp + "\" name=\"productRegs[" + temp + "].serialNo\" value=\"" + "\" class=\"productSerialNo\" maxlength=\"18\" />"
+ "<a class=\"fancybox\" id=\"btnImgSerialNo" + temp + "\" href=\"#divSerialNo" + temp + "\"><img class=\"btnImgSerialNo\" src=\"Images/landing_14.gif\" /></a>"
+ "<span id=\"snFlag" + temp + "\" class=\"redWarning\"></span></td>"
+ "<td><input type=\"text\" id=\"productRegDate" + temp + "\" name=\"productRegs[" + temp + "].PurchaseDate\" readonly=\"readonly\" />"
+ "<span id=\"snRegDate" + temp + "\" class=\"redWarning\"></span></td>"
+ "<td align=\"center\"><img style=\"cursor:pointer\" id=\"btnImgDelete\" src=\"Images/btn_remove.gif\" onclick=\"javascript:removeProductRow('" + guid + "')\" /><div style=\"display:none;\"><div id=\"divSerialNo" + temp + "\" style=\"font-family:verdana;font-size:11px;width:600px\">" + serialnumbergeneral + "<br /><br />" + getSNImageByCategory(productId) + "</div></div></td>"
+ "</tr>";
$(".ProductRegistrationTable").append(szHTML);
$("a.fancybox").fancybox();
//initialization
$("#productRegDate" + temp).datepicker({
minDate: new Date(1996, 1 - 1, 1),
maxDate: 0
});
//sanity check
//s7test
alert('1 '+$("#spanProdID" + temp));
alert('2 '+$("#productRegsID" + temp));
} //end function addNewProductRow
i need the id to be refreshed when the user select a new product, but putting another span tag beside it shows that the span will have the new id will the hidden input will still have the previous id.
is there an elegant way to workaround this issue?
thanks
Moved here after reading @pruts comment ;)
my boss found the answer, it was a simple autocomplete="off" added to the input attributes, although vwd will flag it as an error :)
这篇关于如何防止谷歌浏览器缓存我的输入,尤其是当用户点击后隐藏的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!