How to get the full URL in Express?

The protocol is available as req.protocol. docs here Before express 3.0, the protocol you can assume to be http unless you see that req.get(‘X-Forwarded-Protocol’) is set and has the value https, in which case you know that’s your protocol The host comes from req.get(‘host’) as Gopal has indicated Hopefully you don’t need a non-standard port … Read more

Using the GET parameter of a URL in JavaScript [duplicate]

Here’s some sample code for that. <script> var param1var = getQueryVariable(“param1”); function getQueryVariable(variable) { var query = window.location.search.substring(1); var vars = query.split(“&”); for (var i=0;i<vars.length;i++) { var pair = vars[i].split(“=”); if (pair[0] == variable) { return pair[1]; } } alert(‘Query Variable ‘ + variable + ‘ not found’); } </script>

How do I decode a URL parameter using C#?

string decodedUrl = Uri.UnescapeDataString(url) or string decodedUrl = HttpUtility.UrlDecode(url) Url is not fully decoded with one call. To fully decode you can call one of this methods in a loop: private static string DecodeUrlString(string url) { string newUrl; while ((newUrl = Uri.UnescapeDataString(url)) != url) url = newUrl; return newUrl; }

How to get the anchor from the URL using jQuery?

For current window, you can use this: var hash = window.location.hash.substr(1); To get the hash value of the main window, use this: var hash = window.top.location.hash.substr(1); If you have a string with an URL/hash, the easiest method is: var url=”https://www.stackoverflow.com/questions/123/abc#10076097″; var hash = url.split(‘#’).pop(); If you’re using jQuery, use this: var hash = $(location).attr(‘hash’);

Is there a way to change the browser’s address bar without refreshing the page?

With HTML5 you can modify the url without reloading: If you want to make a new post in the browser’s history (i.e. back button will work) window.history.pushState(‘Object’, ‘Title’, ‘/new-url’); If you just want to change the url without being able to go back window.history.replaceState(‘Object’, ‘Title’, ‘/another-new-url’); The object can be used for ajax navigation: window.history.pushState({ … Read more

How do I get the different parts of a Flask request’s url?

You can examine the url through several Request fields: Imagine your application is listening on the following application root: http://www.example.com/myapplication And a user requests the following URI: http://www.example.com/myapplication/foo/page.html?x=y In this case the values of the above mentioned attributes would be the following: path /foo/page.html full_path /foo/page.html?x=y script_root /myapplication base_url http://www.example.com/myapplication/foo/page.html url http://www.example.com/myapplication/foo/page.html?x=y url_root http://www.example.com/myapplication/ You … Read more