在url中查找字符串位置并替换url

Uff*_*ffo 1 html javascript html5

所以,让我说我目前正在:

http://example.com/page/1/foo/something/here
Run Code Online (Sandbox Code Playgroud)

所以我需要做的是搜索一个特定字符串的window.location.href,在本例中为"foo",我需要在字符串foo之前输入url,所以在这种情况下将是

http://example.com/page/1/
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

Vis*_*ioN 5

有很多方法.这是最短的:

'http://example.com/page/1/foo/something/here'.split('foo')[0]
Run Code Online (Sandbox Code Playgroud)