Reputation: 878
I'm building an animal feed supplying website using C# .NET
It has those features below: http://localhost:52000/Account/Index =>show a list of accounts (ID, name...).
Click on an ID from Index page, it leads into Detail page: http://localhost:52000/Account/Details/6cc608a5-3b4b-4c6f-b220-3422c984919a
In account detail's page, it also has 2 buttons(functions): Delete account and Edit account information.
All I want is after deleting an account (in Detail view), website will redirect to the previous available page (Index,...). Therefore I use window.location.href = "/Account/Index/";
in Delete function.
Here is my delete function with redirecting solution:
function deleteAccount(id) {
var data = { 'id': id };
$.ajax({
*//....*
success: function (result) {
if (result) {
*//redirect to the previous page (Index)*
window.location.href = "/Account/Index/";
}
}
});
}
However,after deleting and redirecting to "/Account/Index/"
successfully, if Admin click on Back Button on Browser, website redirect to unavailable page (the Detail page of that deleted account: http://localhost:52000/Account/Detail/6cc608a5-3b4b-4c6f-b220-3422c984919a).
Then I tried to use window.history.back();
, window.history.go(-1);
, window.location.replace("/Account/Index/");
in turn instead, it worked perfectly only when Admin just deletes that account, if Admin Edits this account first then updates then deletes (Press Edit in Detail view -> Go to Edit view -> press Update -> Go back to Detail View )
--> website redirect to unavailable page (the editing page of that deleted account: http://localhost:52000/Account/Edit/6cc608a5-3b4b-4c6f-b220-3422c984919a).
function deleteAccount(id) {
var data = { 'id': id };
$.ajax({
*//....*
success: function (result) {
if (result) {
*//redirect to the previous page (Index)*
window.history.back();
// or window.history.go(-1)
//or window.location.replace("/Account/Index/");
}
}
});
}
Is that possible to remove the unavailable URLs (those include ID of deleted account) in browser? How can I handle the Back Button in Browser to go through those unavailable URLs? (http://localhost:52000/Account/Detail/6cc608a5-3b4b-4c6f-b220-3422c984919a and http://localhost:52000/Account/Edit/6cc608a5-3b4b-4c6f-b220-3422c984919a)
Upvotes: 1
Views: 740
Reputation: 15200
You could try with the following:
window.location.replace("/Account/Index/");
This is the equivalent of an HTTP redirect using Javascript.
When you use window.location.href
it would be as if a user has clicked on a link and therefore you can go back to the previous URL afterwards.
Upvotes: 2