This question already has answers here:
How can I get query string values in JavaScript?
(73 answers)
Closed 4 years ago.
I have this URL https://localhost/test.html?view=1111&project=1000.
How would i write java script function to fetch the variable project..?
A cool trick is to split your URL with project= and take the second element :
const url = "https://localhost/test.html?view=1111&project=1000"
console.log( url.split("project=")[1] )
Related
This question already has answers here:
javascript - Convert array to string while preserving brackets
(2 answers)
Closed 5 years ago.
[1,2].toString() is "1,2",toString() cannot achieve
how to turn arrays[1,2] into string "[1,2]"
var a=[1,2,3]
var b=a.toString()
b="1,2,3"
Try this it may help you.
var a=[1,2,3];
var b=a.toString();
b = '"'+b+'"';
alert(b);
This question already has answers here:
Getting values from query string in an URL using AngularJS $location
(10 answers)
Closed 5 years ago.
I have a simple line of code that gets me the current path location using AngularJS :
$location.path()
Which results in the following format: /stringValue/intValue/stringValue for example - test/1234/testing
What would be the simplest way to extract the intValue from what $location.path() returns?
This will extract numbers from you url:
var r = /\d+/;
var s = "/string/12345/string2";
alert (s.match(r));
This question already has answers here:
Parse XML using JavaScript [duplicate]
(2 answers)
Closed 5 years ago.
I simply need to extract some info between two tags, in this case, <wsse:BinarySecurityToken>
For example:
<wsse:BinarySecurityToken att1="abc" att2="cd3" att3="adfa">This is a text I need!!!===</wsse:BinarySecurityToken>
I tried
match = text.match(/<wsse:BinarySecurityToken[.*]>([^<]*)<\/wsse:BinarySecurityToken>/g)
does't work!
Or is there anything better than regex? I use angularJs 1
You want to do:
match = text.match(/<tag1.*>([^<]*)<\/tag1>/g)
This question already has answers here:
JavaScript - Get Portion of URL Path
(6 answers)
Closed 8 years ago.
If the current url is: "https://stackoverflow.com/questions/ask"
What's a good way to just get: "questions/ask" ?
You could use
window.location.pathname.substring(1)
You would use window.location.pathname
console.log(window.location.pathname.substring(1));
This would output everything after the first /
This question already has answers here:
How can I get query string values in JavaScript?
(73 answers)
Closed 9 years ago.
Wondering if someone could help with out with creating a regex..
Basically, taking an iFrame's src, and seeing if it's from SoundCloud. If it is, return its id. For example:
var src = 'http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F85110490&auto_play=false&show_playcount=false&show_user=false&show_comments=false&buying=false&liking=false&sharing=false&show_artwork=false&color=00e7ff';
function soundcloudId(src) {
var p = /___________/;
return (src.match(p)) ? RegExp.$1 : false;
}
soundcloudId(src);
And as a result, it would run the "src" through the regex, and if a soundcloud link, would return 85110490. Otherwise, false.
Try this regex:
/http:\/\/w.soundcloud\.com\/.*%2Ftracks%2F([0-9A-F]+)/
Runnable example: http://jsfiddle.net/mYf6P/