How do I detect a URL using javascript?
For example, if i have mywebsite.com/video/r739cw3#1, I want to execute a JS function that will convert this URL to a link
var url = window.location.href;
Try this document.URL
for Example
alert(document.URL);
Related
Having this kind of endpoing:
https://hey.com/p1/m/p2
I want to get rid of the https://hey.com and get only the /p1/m/p2 part on the Pre-request Script. I know I can do it using request.url.replace(/^.*\/\/[^\/]+/, ''), getting the desired output /p1/m/p2.
Is there any other way to do it without using replace or regex? Something like request.url.pathname (which is not working, obviously).
The URL above is just an example, the endpoints and urls will vary.
Bear in mind that I'm using the Pre-request Script on the Postman environment and some things may not work.
Thank you so much.
You should be able to use the URL browser API to construct a URL object.
(new URL(request.url)).pathname
If you're using the desktop version, you can use the built-in node.js API.
var URL = require('url');
URL.parse(request.url).pathname
You can try something like this
var fullUrl = request.url.split('/');
fullUrl.splice(0,3);
var url = a.join('/');
console.log(url);
I'm trying to get the url path with it's current url queries using uiRouter.
What I want to achieve is something similar to:
window.location.pathname + window.location.search
How would one achieve this via uiRouter?
I've tried console logging $location but the path doesn't bring the url query, just the path.
you can try with below code to get full url with all segments.
// given URL http://yoururl.com/#/some/path?val1=bar&val2=xoxo
var absUrl = $location.absUrl();
// "http://yoururl.com/#/some/path?val1=bar&val2=xoxo"
Thanks
I have a url path as shown below.
http://localhost:12534/urlpart1/urlpart2?querystring=140
So I need to replace the "urlpart2" with the "urlpart3" by using javascript or anugularjs.How can I do that.I can get the whole url by using:
var urlPath = window.location.href;
Any help would be highly appreciated.
If you just need to replace specific substring urlpart2 you can go with simple replace method:
var urlPath = window.location.href;
var newUrlPath = urlPath.replace('urlpart2', 'urlpart3');
This is an example URL.
http://stackoverflow.com/questions/ask?a=1&b=2
question: I need to fetch path name along with url values like this/questions/ask?a=1&b=2
I need jquery or javascript solution
var url = document.createElement('a');
url.href = 'http://stackoverflow.com/questions/ask?a=1&b=2';
alert(url.pathname + url.search);
Demo: http://jsfiddle.net/karim79/8XYYj/
I'm searching for a jquery plugin for full URL manipulation (parsing, building).
Example:
var url = 'http://mypage.com/?param=1'
var params = $.getParams(url) # {param: 1}
var newUrl = $.newUrl(url, {param:2}) # 'http://mypage.com/?param=2'
Thx.
To convert a JavaScript object into a URL parameter string you can use the jQuery param method:
$.param({a:1, b:"Test 1"}) // gets: "a=1&b=Test+1"
To parse a URL parameter string into a JavaScript object use this solution.
There is this jquery plugin https://github.com/allmarkedup/jQuery-URL-Parser that I used once. But once you console.log window.location you will see that it is not so hard to do it your self.
I never tried this one: http://urldecoderonline.com/javascript-url-decode-jquery-plugin.htm but it seems it can build URL to.
Have fun