A Star
A Star

Reputation: 627

Javascript not reloading page when using location.replace a second time with the same URL

I am using location.replace to reload a page that uses GET variables for a success message.

My problem is, if the URL in the location.replace is exactly the same the page does not reload. I know that if I can use a condition and use location.reload() this will answer my question by I do not know how to use an IF statement on a location.replace, or any other way this could be done.

So when calling the location.replace('?success=1'); whilst ?success=1 is already in the URL the page does not reload.

Could anyone shed some light on this?

Thanks

Upvotes: 2

Views: 1987

Answers (1)

bugwheels94
bugwheels94

Reputation: 31920

 if(window.location.href.match(/[?]success=1/))
    window.location.reload();
    else
    window.location.replace('?success=1')

Upvotes: 2

Related Questions