1

So let's say that i'm currently on:

http://example.com/page/1/foo/something/here

So what I need to do, is to search for window.location.href for a specific string, in this case "foo", and I need to url before the string foo, so in this case will be

http://example.com/page/1/

How can I achieve this?

1 Answer 1

5

There are many ways. Here is the shortest:

'http://example.com/page/1/foo/something/here'.split('foo')[0]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.