How to link a webpage to itself without first knowing its name? - html

To link a page to itself (e.g. http://example.com/folder/ThisPage.html), we can simply create a href as such:
ThisPage.html:
Link
This works, but has the disadvantage of needing to be updated when the file name changes. For example, if the file name changes to ThatPage.html, our href needs to change accordingly to Link.
I'm looking for an alternative without that disadvantage. I've tried:
Link
Doesn't work as Link does, because it appends a "blank query part" (question mark) to the URL.
Link
Doesn't work as Link does, on some browsers (e.g. Opera).
How do we link a page to itself, without having to update the relevant portion when the name of the page changes?
Note: JavaScript not allowed.

Just use Link. Nobody cares about the question mark appended to the URL. It does the requirement and that is what counts right?

It's very simple, just leave the href="" blank. So that's how:
Click me to refresh page
But this is not necessarily a good idea, because the cache may not be cleared, and whatever you need it for, if the page has changed in the meantime the change may not appear despite the reload. Probably a better idea is the javascript code location.reload(); to take. But there are enough explanations on other sites, which is why I won't explain it here. You can of course also for example take a question mark (?), but this is unnecessary, actually not intended for it and can cause problems depending on the program.
Here is a short list of common hyperlinks:
Points to the root page
Link
Points to a file relative to the root page
Link
Points to a file relative to the current file
Link
Points to a file in the previous folder
Link
Points to a file in the second previous folder
Link
Points to a file in a folder below
Link
Points to the current file
Link
Points to a page with a different host but the same protocol
Link
I hope that my answer will help some people, because I found it via a search engine and saw that there is no correct answer. And it's my first answer here 😅

If you want it to go nowhere, you can use
link
But if you want it to reload the page, you'll have to go with JavaScript.
If you want to reload the page you could use the Meta refresh tag
http://www.w3.org/TR/WCAG20-TECHS/H76.html

If you want to reload the page, you really should take a look into javascript. It is the best way to do it.

Just do this:
This Very Site
Source: I saw this in the source code of Matthew Alger's website. Check it out for yourself!

Why not try ?
I looked some things up, and as it turns out, ./ refers to current directory.

You can just make a link to the same page.

Here ya go. Hope this is what you are looking for
Link

Related

Extracted URL not redirecting

I am looking at the following site: https://www.lg.com/us/press-release.
I need to get a link to go directly to the computers tab, and it needs to be a url.
I extracted and tried: https://www.lg.com/us/press-release#press-list5 however this still redirects.
Can someone tell me what the URL is to go directly to the computer tab please?
Thanks
I don't think a URL is going to work. I believe there's some Javascript at work here.
Why?
Before/Unclicked:
Computers
After/Clicked:
Computers
So once it's clicked, the list item has the active class added and the aria-selected attribute set to true. So a URL with a bookmark doesn't look like it'll work.

Do I need to update CSS to upload new images?

I want to start by saying that I did not build said website. I was given FTP access to the site and can download it's entirety.
What we are interested in is replacing the images as they are rather outdated.
If I replace the images (naming them as the ones that exist as of right now), they update just fine.
But adding more does not. Lets say that files are numbered 1-6. If I replace those with the same name, they change. If I add 7.jpg, for example, it does not show in the gallery.
Do I need to update the CSS code or upload it again?
I can provide the code in turn.
Without further details it's hard to tell what the problem is, but it looks like either someone hard-coded CSS or hardcoded HTML. But I would really need to see the code.
Please try to copy/paste at least the code for file that should render the images.
Your gallery should contain new images' name.
if you upload 7.jpg, this one is not in your gallery I guess.
I think it will not matter if you update the CSS.
A priori, to clear any doubt if the images are in cache, I suggest you refresh the page by typing ctrl + R or open a tab in incognito mode.

HTML remove url variables, NO PHP or JS solution

My site uses both PHP and the JS AJAX so I'm fairly familiar with them both, and I don't want a solution that includes them. I have this page structure where all my users stay on just one landing php page, which then fetches the right content depending on the URL's p variable.
http://www.example.com/?p=about
http://www.example.com/?p=aMap-anothermap-evenAnothermap-lastelyTheFile
This page structure works great for me except that I don't know the right way to make a link that just removes the whole ?p=home. Because I want my home/start page to be variable free. I want it to be
http://www.example.com/
rather than
http://www.example.com/?p=home
Now I could just make the link
http://www.example.com/?
And then just remove the ? with the JS pushState(), but that would look pretty silly and would only work for JS users.
Let's say i would want to the do the above example with just the ? then I could create a link like this.
Link
<script src="SomeCoolPushStateScript"></script>
And I know from experience that this doesn't even work:
Link
So here comes the question: How do I remove the ?variable=something part of an URL when using an HTML href?
The path ./ should do the trick.
Link
If you want to preserve the main script name, like index.php, you will have to include that name.
Link
Alternately, you could dynamically generate domain-relative or absolute URL's with PHP.
You don't need to use querystrings.
Link
would go to example.com's root.
I don't recommend using "./". This would do what you want if the user is on a page that is in the root directory of your website (e.g. http://www.example.com/page.html). However, this would not work if they were on a page in a subdirectory. E.g. if the user's on http://www.example.com/hello/page.html, it would just link to http://www.example.com/hello/.
Using "/" makes sure the user goes to the root of your website.

Link to current page html

Have been searching some topics but don't think I have found the exact answer I was looking for hence I try here. In my Wordpress website I have a hardcoded button on around 150 pages on each top of a page. I would like to link to an angor text /#anchor halfway of each of this pages.
Now I don't want to enter every specific URL manually. Is there a HTML trick where you refer to the current URL, something in the order of: .com/currentpage/#anchor?
Thanks in advance for any help or tips.
You can add a link on current page without add a page url.
For hash
Link
For QueryString
Link

Parsing relative links on a html page

I'm trying to parse a page to find all valid urls, but here is a problem. There are 3 types of links on a page: url (_http://site.com/dir/page.html), absolute uri (/dir/page.html) and relative uri (dir/page.html without starting slash). Probably i'm wrong about terminology, i'm not an html coder. But that's not the case in any way.
I need to find and collect all urls (i.e. _http://site.com/dir/subdir/page.html and so on). And here is the problem. If there is a page _http://site.com/dir/page.html with a link like link it's supposed to bring us to _http://site.com/dir/subdir/page.html. But if there is <base href="/"> in the head section of a page, same link leads to _http://site.com/subdir/page.html i.e. different from _http://site.com/dir/subdir/page.html.
The question is if there can be anything else in html code on a page that can influence target url.
Thanks in advance.
In HTML as such there is nothing else beside the href base You mentioned
What could become tricky and should be considered is that there might be linkage on page made by script execution, so things like window.location.href = something. This would be easy if the links are clearly stated, but they might be also computed by the script and then You could miss the link or mis-read it by using simple parsing.
Your problem is actually how url linking in html works, please read: http://www.webdevelopersnotes.com/design/relative_and_absolute_urls.php3 . So say you're in /admin/ and you need /admin/login.aspx . My relative URL is login.aspx, while my absolute is /admin/login.aspx make sense?
So basically what I'm saying is consider which directory your link is being served out of. That will determine the type and content of the url link to use.
Other than that, as stated already, jscript and server side code can also do linking.