I want to compose a link with several GET parameters gathered from variables. For example: In JavaScript, if I have variables var1, var2 and var3 set already to the corresponding values, I know the link can be composed by concatenating strings and the variables as follows: Is there a cleaner or better way to do this? In jQuery, the AJAX
Tag: url
How do you get the file size of an image on the web page with Javascript?
I’d like to be able to get the file size on an image on a webpage. So let’s say I have an image on the page (that has loaded) like this: How do I call a function in Javascript (or, even better, jquery) to get the file size (not the dimensions) of the image? It’s important to note that I’m
remove last directory in URL
I am trying to remove the last directory part of an URL. My URL looks like this: https://my_ip_address:port/site.php?path=/path/to/my/folder. When clicking on a button, I want to change this to https://my_ip_address:port/site.php?path=/path/to/my. (Remove the last part). I already tried window.location.replace(//[A-Za-z0-9%]+$/, “”), which results in https://my_ip_address:port/undefined. What Regex should I use to do this? Answer Explanation: Explode by “/”, remove the last element
Get path and query string from URL using javascript
I have this: I want this: how do i do this in javascript? I tried window.location.href but it is giving me whole url I tried window.location.pathname.substr(1) but it is giving me found-locations/ Answer Use location.pathname and location.search:
How do I get the fragment identifier (value after hash #) from a URL?
Example: Using jQuery, I want to put the value hello in a variable: Answer No need for jQuery Since String.prototype.substr is deprecated use substring instead.
Get the first part of a url path
If I have a url like: http://localhost:53830/Organisations/1216/View I want to alert the first part of the url path in lowercase format e.g. ‘organisations’ So far I have: but it’s not working as intended. Can anyone help? Thanks Answer
If domain specified not equal to then current URL apply this jQuery as well as pages with same domain
The code below only shows <span> on http://example.com/ but wont show <span> on http://example.com/files/target.html so how can I get it to work on all pages with the specified domain? Please help. Answer What you wrote doesn’t work because window.location returns a Location object, which is a host object. The variable myurl is a string. When comparing a string and an
Redirecting child iframe to relative url, using js within iframe – but url is relative to the parent
Some interesting behavior that I didn’t expect. I have a page which contains an iframe, and in that iframe there’s a javascript function that redirects its own window. I call the iframe’s js function from the parent frame. My expected behavior is that it will redirect the iframe to a new page, relative to the iframe’s existing location. Instead, it
RegEx to match stuff between parentheses
I’m having a tough time getting this to work. I have a string like: And I need regex or a method of getting each match between the parentheses and return an array of matches like: The regex I’m using is /((.+))/ which does seem to match the right thing if there is only one set of parenthesis. How can I
Difference between document.URL and location.href
I know that document.URL can not be set, while location.href can. But the Document indicates: URL is a replacement for the DOM Level 0 location.href property. So when would we use document.URL? Answer You can get the document.URL, but you can not set it. You can both get and set the location.href. In some webbrowsers, you are able to set