Pregunta

Say I have this URL:

http://www.domain.com/subpage/?somsearch#somehash?

Is there a standard way to get the following result, without hash and search:

http://www.domain.com/subpage/

This is how I do it now:

var windowLocation = window.location;
alert(windowLocation.protocol + '//' + windowLocation.hostname + windowLocation.pathname);
¿Fue útil?

Solución

Thanks to Bergi, this is pretty simple:

http://jsfiddle.net/8Vr7n/3/

var url = "http://google.com/?search=bob#asdf";

var shorterUrl = url.split("#")[0].split("?")[0];

alert(shorterUrl);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top