문제

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);
도움이 되었습니까?

해결책

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top