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 /
Related
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] )
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:
How to remove the hash from window.location (URL) with JavaScript without page refresh?
(17 answers)
Closed 8 years ago.
This is my url:
http://example.com/index.php#motto
On page load remove #motto with Javascript.
try this: window.location.hash=""
$.fn.urlHash = function()
{
return window.location.hash.replace('#','');
};
$.urlHash();
This question already has answers here:
Redirect faster with Greasemonkey (or similar userscript engine)?
(3 answers)
Closed 9 years ago.
i want to redirect from the first link to the other using javascript or jquery in greasemonkey
http://*.tumblr.com/post/*/*
http://$1.tumblr.com/image/$2
Use this regex
/^http:\/\/(.*).twitter.com\/post\/(.*)\/(.*)/g
Like this
var regexp = new RegExp(/^http:\/\/(.*).twitter.com\/post\/(.*)\/(.*)/g);
var results = regexp.exec(window.location.href);
To create your array, then you can
if(results){
window.location="http://"+results[1]+".twitter.com/image/"+results[2]+"/"+results[3];
}
To redirect
Live Version
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Get query string values in JavaScript
the link is
http://nycs00058260/sites/usitp/_layouts/CreateWebPage_DingDing.aspx?List={74AB081E-59FB-45A5-876D-284607DA03C6}&RootFolder=%3b&Text=%27MDNSO%27
how can I parse the parameter "Text"(at the end) from the url using javascript?
anyone can help me?
URI.js is a small library that makes working with URLs nice and easy :)
var url = new URI("http://nycs00058260/sites/usitp/_layouts/CreateWebPage_DingDing.aspx?List={74AB081E-59FB-45A5-876D-284607DA03C6}&RootFolder=%3b&Text=%27MDNSO%27");
var queryMap = URI.parseQuery(url.query());
var text = queryMap["Text"];
console.log("Text: ", text);
You can combine window.location.search : https://developer.mozilla.org/en-US/docs/DOM/window.location
with indexOf : https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/indexOf
and substring: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/substring