I’m being bugged by this issue which I’m facing with location.replace. I need to simulate an HTTP redirect (I don’t want my users to get stuck in a never-ending back button fiasco for this particular piece of functionality I’m implementing) so I’m using location.replace instead of location.href to redirect. However, I constantly end up on getting the below error message in my console on Firefox 12.0.
Permission denied to shadow native property
Below is my code (I’m masking off my server details from the request URL while adding the code here)
$(document).ready(function() {
$(".workout_sel_month").click(function() {
month_number = $(this).attr('id').replace(/month/g,"");
weekwise_workout_url = "http://www.example.com/viewrecord/getscheduleformonth";
location.replace = weekwise_workout_url + "&month_number=" + month_number;
});
});
Please note that if I use location.href instead it works like a charm. What may be the cause of this? . If this is a duplicate post (I did some basic search and found some posts but none of them particularly suited my case), my sincerest apologies and in that case please link me up with the appropriate question here. 🙂
location.replaceis a function. By assigning a value to the property you are trying to override it (which you are not allowed to).location.hrefon the other hand just contains a string which you are allowed to change.See the MDN documentation.
To clarify a bit more:
The fact alone that
location.replaceis a function does not imply that this property is immutable, but it makes the decision to do so understandable:Functions are supposed to be called, they should not be overridden. I assume that’s why this property is immutable as opposed to others. Properties containing strings, numbers, etc. are more likely meant to be changed.
But any property could be marked as immutable, no matter its value.