Monday 27 November 2017

javascript - Split text from url





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?



Answer




Try using href="https://developer.mozilla.org/en-US/docs/Web/API/URL/searchParams" rel="nofollow
noreferrer">URL.searchParams




class="snippet" data-lang="js" data-hide="false" data-console="true"
data-babel="false">

class="snippet-code-js lang-js prettyprint-override"> //
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"));





No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...