<a href> appends link to end of current url
You should really learn about absolute and relative paths. What you're using is a relative path.
This is an absolute path on your server:
<img src="/images/logo.png">
This is an url with http protocol - opens Google.com
<a href="http://google.com">Google</a>
This is an url without explicit protocol, it will turn into http or https based on what your page uses:
<a href="//google.com">Google</a>
Use one of those for what you need (typically the http one).
HTML Urls - how to append to the existing url
<base href="/mypage/ladeda/" />
...
<a href="1/">(goes to http://domain.com/mypage/ladeda/1/)</a>
Via the <base>
element.
But!<a href="1/">Page 1</a>
should take you to http://domain.com/mypage/ladeda/1/
already provided that (a) you don't use a <base>
element already and (b) the current resource is really http://domain.com/mypage/ladeda/
(with a trailing slash).
How to append current path ending to href in body link
You could implement it like so:
const idx = location.href.lastIndexOf('/');
const lastPart = idx !== -1 ? location.href.slice(idx + 1): "";
document.querySelectorAll('a').forEach(a=>a.href+=lastPart);
Appending current URL parameters onto anchor link
Use window.location.search
:
var url = "https://exmaple.com";
var newurl = url + window.location.search;
newurl
will contain all the get
(ex. ?something=something&something2=something5
) data.
To change the href
of a
:
var button = document.getElementById('#ptsBlock_553944');
button.href = button.href + window.location.search;
href is adding the url at the end of current url
Url.Content is used when you wish to resolve a url for any file or resource on your site and you would pass it the relative path:
@Url.Content("~/path/file.htm")
Url.Action is used to resolve an action from a controller such as:
@Url.Action("ActionName", "ControllerName", new { variable = value })
you will have to add the action in your controller :
public YourControllerController : Controller
{
public ActionResult YourAction() { /* stuff */ }
}
jQuery - Append hash to href from current URL
Check if window.location.hash
is set and that it isn't just a '#'
then apply to the anchor
// for demo only set hash
history.pushState(null, null, '#someVal')
const urlHash = location.hash,
langLink = document.querySelector('#lang');
if (urlHash && urlHash !== '#') {
langLink.hash = urlHash;
}
console.log('New href=',langLink.href)
<a id="lang" href="https://www.example.com/en.html">Change Language</a>
Anchor tag appending field value to current url instead of just navigating to field value
It sounds like some links stored in your website_link
are relative urls. If they don't start with //
or http://
or equivalent, you will get the result you're seeing.
HREF= automatically adds to current page URL (in PHP). Can't figure it out
This is how a browser interprets and empty href. It assumes you want to link back to the page that you are on. This is the same as if you dont assign an action to a <form>
element.
If you add any word in the href it will append it to the current page unless you:
- Add a slash
/
to the front of it telling it to append it to your base url e.g.http://www.whatever.com/something
- add a
#
sign in which case it is an in-page anchor - or a valid URL
EDIT: It was suggested that I add a link to help clarify the situation. I found the following site that I think does a really good job explaining the href
attribute of anchor tags and how it interprets URL paths. It is not incredibly technical and very human-readable. It uses lots of examples to illustrate the differences between the path types: http://www.mediacollege.com/internet/html/hyperlinks.html
Related Topics
Word Wrap a Link So It Doesn't Overflow Its Parent Div Width
How to Make Full Height Cell in Full Height Table in Internet Explorer
Responsive Table Handling in Twitter Bootstrap
How to Avoid Ie8 Compatibility Button
How to Detect Only with CSS Mobile Screens
How to Place Text and an Image Next to Each Other in HTML
How to Get Flexbox to Include Padding in Calculations
CSS Grid with Variable Number of "Auto" Rows, But One Row Should Take "1Fr"
How to Make a Fixed Column in CSS Using CSS Grid Layout
Why Is Padding Expanding a Flex Item
Make a Parent Div Webkit-Filter Not Affect Children
Inline Svg Vs Svg File Performance
Getting Rid of Bullet Points from <Ul>
Is There a Jdk Class to Do HTML Encoding (But Not Url Encoding)