Questions tagged [url]

A URL (Uniform Resource Locator), is a universal identifier on the web. A URL is a reference to a web resource at a specific location, and provides a means for retrieving that resource.

The syntax and parsing behavior for URLs is defined in the URL Living Standard web page - this is the current URL standard.

Basically URL has 3 parts:

  • the URL prefix, which specifies the protocol used to access the location
  • the server name or IP address of the server
  • the path to the directory or file(resource)

References

Related tags

43477 questions
543
votes
38 answers

Check if a JavaScript string is a URL

Is there a way in JavaScript to check if a string is a URL? RegExes are excluded because the URL is most likely written like stackoverflow; that is to say that it might not have a .com, www or http.
Bruno
  • 8,497
  • 13
  • 38
  • 55
518
votes
38 answers

Fixed page header overlaps in-page anchors

If I have a non-scrolling header in an HTML page, fixed to the top, having a defined height: Is there a way to use the URL anchor (the #fragment part) to have the browser scroll to a certain point in the page, but still respect the height of the…
Tomalak
  • 332,285
  • 67
  • 532
  • 628
504
votes
26 answers

How do I parse a URL into hostname and path in javascript?

I would like to take a string var a = "http://example.com/aa/bb/" and process it into an object such that a.hostname == "example.com" and a.pathname == "/aa/bb"
freddiefujiwara
  • 57,041
  • 28
  • 76
  • 106
493
votes
37 answers

Adding a parameter to the URL with JavaScript

In a web application that makes use of AJAX calls, I need to submit a request but add a parameter to the end of the URL, for example: Original URL: http://server/myapp.php?id=10 Resulting URL: http://server/myapp.php?id=10&enabled=true Looking…
Lessan Vaezi
  • 6,927
  • 3
  • 25
  • 15
490
votes
8 answers

Redirecting to a relative URL in JavaScript

My problem is that I want to redirect via JavaScript to a directory above. My code: location.href = (location.href).substr(0, (location.href).lastIndexOf('folder')) The URL looks like…
user199337
  • 8,063
  • 7
  • 23
  • 18
475
votes
21 answers

How to check if the URL contains a given string?

How could I do something like this: