I want to make sure that the URL I get from window.location
does not already contain a specific fragment identifier already. If it does, I must remove it. So I must search the URL, and find the string that starts with mp-
and continues until the end URL or the next #
(Just in case the URL contains more than one fragment identifier).
Examples of inputs and outputs:
www.site.com/#mp-1 --> www.site.com/
www.site.com#mp-1 --> www.site.com
www.site.com/#mp-1#pic --> www.site.com/#pic
My code:
(that obviously does not work correctly)
var url = window.location;
if(url.toLowerCase().indexOf("#mp-") >= 0){
var imgString = url.substring(url.indexOf('#mp-') + 4,url.indexOf('#'));
console.log(imgString);
}
Any idea how to do it?
#mp-1
or#mp-
. – Lalia