Answered by:
window.location.href doesn't work on IE Refresh

Question
-
User457850011 posted
I am trying to give users a link to click to export an item to excel. The link words fine on first page load but as soon as the page is refreshed the click event for the link doesn't work. Below is my code. Any help would be appreciated.
public FileResult ExportToExcel(int Id)
<span style="float: right" class="glyphicon glyphicon-export"
data-toggle="tooltip"
data-placement="top"
title="Click here to export to Excel."
id="@string.Format("Export-{0}", item.Id)"></span>$(".glyphicon-export").click(function(e) {
e.preventDefault();
e.stopPropagation();
const rawId = this.id;
const id = rawId.split("-")[1];
window.location.href = "/ControllerExport/ExportToExcel?Id=" + id;});
Sunday, September 29, 2019 7:33 PM
Answers
-
User457850011 posted
Hi
Rather than trying to guess what happens by reading your code, just look at what actually happens using tools such as F12 Console.
Yes I did before asking the question. Anyway I have figure it out and fixed the issue I was facing. Below is my solution and it works perfectly well for my situation
<span style="float: right" class="glyphicon glyphicon-export" onclick="location = '/ControllerExport/ExportToExcel?Id=' + @item.Id"
data-toggle="tooltip"
data-placement="top"
title="Click here to export to Excel.">
</span>- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, October 4, 2019 5:31 PM
All replies
-
User-17257777 posted
Hi denkyira,
According to your description, I have created a test demo on my side, it works well. My test result as below:
Codes:
Controller:
public ActionResult ExportToExcel(int Id) { string fullPath = Server.MapPath("~/App_Data/info.txt"); return File(fullPath, "application/octet-stream", "info.txt"); }
View:
<span style="float: right" class="glyphicon glyphicon-export" data-toggle="tooltip" data-placement="top" title="Click here to export to Excel." id="@string.Format("Export-1")"></span> @section scripts{ <script> $(".glyphicon-export").click(function (e) { e.preventDefault(); e.stopPropagation(); const rawId = this.id; const id = rawId.split("-")[1]; window.location.href = "/Home/ExportToExcel?Id=" + id; }); </script> }
Result:
Could you please tell me your IE browser version? Does this issue only happen in the IE bowser? Could you please post more details codes about your view and controller for me to reproduce the issue?
Besides, I suggest you could use F12 bowser develop tool to check If this is any error in it.
Best Regards,
Jiadong Meng
Monday, September 30, 2019 3:31 AM -
User753101303 posted
Hi,
denkyira
doesn't workRather than trying to guess what happens by reading your code, just look at what actually happens using tools such as F12 Console and the js debugger. I suspect you are using maybe an IE version or compatibility level that doesn't support "const" ?
Monday, September 30, 2019 8:48 AM -
User457850011 posted
Hi
Rather than trying to guess what happens by reading your code, just look at what actually happens using tools such as F12 Console.
Yes I did before asking the question. Anyway I have figure it out and fixed the issue I was facing. Below is my solution and it works perfectly well for my situation
<span style="float: right" class="glyphicon glyphicon-export" onclick="location = '/ControllerExport/ExportToExcel?Id=' + @item.Id"
data-toggle="tooltip"
data-placement="top"
title="Click here to export to Excel.">
</span>- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, October 4, 2019 5:31 PM