-1

I have this url

https://myapp.tezze-now.com/sp?id=form&table=user&sys_id=cb6688db0d79b5e9619&view=sp

I need to get text of table name from the url when page loads. I tried this

location.href.split('&')[1]

It returns "table=user". but I need the table name alone as user.

How can I get this?

1
  • 1
    you can split the result using result.split('='); Commented Jul 20, 2018 at 10:33

3 Answers 3

3

Try using URL.searchParams

 // location.href
let str = "https://myapp.tezze-now.com/sp?id=form&table=user&sys_id=cb6688db0d79b5e9619&view=sp"; 

console.log((new URL(str)).searchParams.get("table"));

Sign up to request clarification or add additional context in comments.

1 Comment

Please don't answer obvious duplicates. Close-vote them, instead.
1

Split it once more:

location.href.split('&')[1].split('=')[1]

Or you could use Url class (no support in IE):

var url = "https://myapp.tezze-now.com/sp?id=form&table=user&sys_id=cb6688db0d79b5e9619&view=sp"; //window.location.href
var url = new URL(url);
var table = url.searchParams.get("table");
console.log(table);

1 Comment

Please don't answer obvious duplicates. Close-vote them, instead.
0
location.href.split('table=')[1].split('&')[0]

Don't assume the parameter order ;)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.