IE9 Javascript Undefined Variables
I have the following in my code, which has worked fine in IE 7 and 8, but it no longer works in IE 9 (unless the user runs in compatibility mode of course...)
<asp:Label ID="invNumLink" runat="server" Font-Underline="true" ForeColor="Blue" Text='<%# Eval("Order_No") %>' createDate='<%# string.Format(Eval("create_date").ToString(),"MM/dd/yyyy") %>'
operatorNo='<%# Eval("operator_no") %>' orderNo='<%# Eval("Order_No") %>' loc='<%# Eval("Location") %>' table='<%# Eval("table_no") %>' recall='<%# Eval("recall_code") %>'
orderID='<%# Eval("ID") %>' acrID='<%# Eval("ACR_ID") %>'
onclick="goToDetail(this.orderNo,this.createDate, this.operatorNo, this.loc, this.table, this.recall, this.orderID, this.acrID);" style="cursor:pointer" ></asp:Label>
<script type="text/javascript">
function goToDetail(orderNo, createDate, operatorNo, loc, table, recall, orderID, acrID) {
var URL = 'OrderDetailView.aspx?orderNo=' + orderNo + '&' + 'createDate=' + createDate + '&' + 'operatorNo=' + operatorNo + '&' + 'loc=' + loc + '&' + 'table=' +
table + '&' + 'recall=' + recall + '&' + 'id=' + orderID + '&' + 'acrID=' + acrID;
day = new Date();
id = day.getTime();
window.open(URL, id, 'toolbar=1,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=1100,height=700,left = 62,top = 15')
}
</script>
In IE9 all of the values sent to the "goToDetail" function are undefined. Any ideas on how to fix this?
EDIT
I resolved this by adding the call to javascript from the code behind:
invNumLink.Attributes.Add("onclick", string.Format("goToDetail('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}'); ret开发者_Python百科urn false;", item.GetDataKeyValue("Order_No").ToString(),
string.Format(item.GetDataKeyValue("Create_Date").ToString(), "MM/dd/yyyy"),item.GetDataKeyValue("Operator_No").ToString(), item.GetDataKeyValue("Location").ToString(),
item.GetDataKeyValue("table_no").ToString(), item.GetDataKeyValue("recall_code").ToString(), item.GetDataKeyValue("ID").ToString(),item.GetDataKeyValue("ACR_ID").ToStrin
Thanks,
Aaron
You could use data-attributes, which work like this:
Instead of:
<span operatorNo="value">
You use
<span data-operatorNo="value">
And access it with
this.getAttribute("data-operatorNo")
This works in IE6 and is documented as working in IE7+. Do HTML5 custom data attributes “work” in IE 6?
I know this is UGLY... but maybe passing in the values directly would solve your issue.
<asp:Label ID="invNumLink" runat="server" Font-Underline="true" ForeColor="Blue" Text='<%# Eval("Order_No") %>' createDate='<%# string.Format(Eval("create_date").ToString(),"MM/dd/yyyy") %>'
operatorNo='<%# Eval("operator_no") %>' orderNo='<%# Eval("Order_No") %>' loc='<%# Eval("Location") %>' table='<%# Eval("table_no") %>' recall='<%# Eval("recall_code") %>'
orderID='<%# Eval("ID") %>' acrID='<%# Eval("ACR_ID") %>'
onclick="goToDetail('<%# Eval("Order_No") %>','<%# string.Format(Eval("create_date").ToString(),"MM/dd/yyyy") %>', '<%# Eval("operator_no") %>', '<%# Eval("Location") %>', '<%# Eval("table_no") %>','<%# Eval("recall_code") %>', '<%# Eval("ID") %>', '<%# Eval("ACR_ID") %>');" style="cursor:pointer" ></asp:Label>
For non-standard attributes on an HTML tag, I believe you need to use element.getAttribute("attName")
to fetch non-standard attributes defined in the HTML rather than directly access them with element.attName
. To stay with standards, you should also prefix custom data attributes with "data-".
精彩评论