Relative URL containing just the querystring - html

I have some links in a page which only need to change the querystring portion of the current URL.
E.g. the current page is:
http://demo.com/bigreport?page=13
and I want to link to
http://demo.com/bigreport?page=14
Can I use Next as a relative link for this?
I was surprised to find it works in Chrome. I've never seen it documented or mentioned anywhere, so I'm keen to know if anyone uses this, and if there is wider browser support.

Further research reveals that Next is a valid relative URL.
It's documented as part of WHATWG's URL spec
http://url.spec.whatwg.org/#relative-state
The new URL will inherit the base URL's scheme, host, port and path.
Tested to work on:
Chrome
IE 7

Next works because browsers interpret that as a relative URL. Similar to how linking images on your site might work <img src="logo.gif"/> Relative urls work this way (link is relative to the current page), you don't need to use the full absolute URL.
Browsers have been supporting this for long long time. People might not be aware of it because browser automatically handles it.

Related

Stop Chrome from turning my relative links to absolute links when using 'Save File As...'

Quite simply: I am outputting an html file from a cgi program that uses internal anchors relative to the same document. I wish users to be able to save this file from my url an use that file locally. Which is exactly what you would expect and get from a relative URL, and works in Firefox and IE.
However Chrome is 'filling out' all the relative links in the saved document with the absolute URL from my website location without being asked to.
How can I suppress this behaviour?
Perhaps you could use javascript to parse all links upon loading the page and remove the "absoluteness" of the link and just retain the relative portion.

Relative URL Paths for images

Working on a project which involves crawling some legislation sites and hit a puzzler
This url https://www.legislation.gov.au/Details/F2018L00530
has a base setting of https://www.legislation.gov.au/Details/F2018L00530/Html/Text
in its header but images on the page resolve relative to https://www.legislation.gov.au/Details/F2018L00530/Html/ and I cannot determine why. Its not a frame and I cannot see something else which would change the path.
Apparently if you use the base tag, the browser ignores everything after the last slash. So a base of https://www.legislation.gov.au/Details/F2018L00530/Html/Text
is equivalent to https://www.legislation.gov.au/Details/F2018L00530/Html/
which corresponds to what we are seeing.
Weird, but I tried it with a test page with similar results.

Absolute Links Resolving to Current Domain

My HTML code has never behaved this way before! I have looked around the internet and here and I can't find an answer to this.
The problem is simple: external links do not go to external webpages and instead become internal links
For example:
If I'm on http://www.domain.com where I have an external link
National Aeronautics and Space Administration
When the link is clicked, instead of going to www.nasa.gov or opening a new window for nasa.gov, it goes to http://www.Domain.com/www.nasa.gov
Why is it doing this?
I am certain that your address is missing a / in your actual code.
Test
would resolve to http://www.domain.com/www.nasa.gov/. Note only one slash after the protocol.
Two slashes // indicate your address is absolute (external) whilst one slash / tells the browser to go to the root directory of the current site to find the address (relative). This is because you could change protocol (such as https:) and then give a relative address (such as /path/to/content.html).
Hope this helps.

jQuery Mobile cached page and HTML base href

My multi-page jQuery Mobile app spans a couple directories. One stateful page is cached with data-dom-cache="true". When I navigate to it, the base path used for relative links ($('base')[0].href) isn't restored to the proper subdirectory; it's one level up. Seems like a jQuery Mobile bug.
To work around, I tried $('base')[0].href = 'subdir';. But executing that sends it down a rabbit hole of subdirs. Inside the page it gives me subdir/subdir, and from the Chrome console it's subdir/subdir/subdir.
Is this a quirk of Chrome or jQuery Mobile, and what else can I do to work around? It's not easy for me to test with another browser.
Woops, I forgot to answer this back then. I believe the solution was to add another <base>, rather than modifying the existing tag, to avoid any quirks with relative URLs.

HTML force URL hyperlink to be treated as non-relative (absolute)

I have a list of URLs that our users have entered for websites of various clients... I am loading this list from the server into a grid for the users to see... I made the URLs clickable by wrapping them with a href HTML tag... the problem is, sometimes the user enters urls without the http:// or www. prefix and so the browser treats them as relative URLs which are never ever the case because all these websites are for our clients and they are all external. Is there a way to force these URLs to be treated as absolute instead of relative?
Here is an example:
<a target='_blank' href='google.com'>google.com</a>
If you try this, you'll see that the browser will assume it is a relative path which shouldn't be the case.
Thanks
Solution:
I've chosen to check for '//' (because I don't know what the protocol is - could be http or https) and if not found, I assume it is an http website and I prefix the URL with that - so in short no way to force the browser to treat the hyperlinks as absolute
You can add // before the url and it should work.
Like: //stackoverflow.com
Why don't you preprocess the input and append http:// when necessary?
It is a relative URI.
If you want to link to http://google.com/ then that is where you need to link to.
You can either moderate the URIs you are wrapping, or try to algorithmically guess if it was intended to be a relative link or not.
Note that you cannot safely assume that there should be a www. since the use of that for websites is just a convention, and no longer a strongly followed one.