How to get URL without context path?
I am using spring boot 1.5.18.RELEASE and Thymeleaf
I tried this two possibilities.
<a th:href="#{${website}}" target="_blank"> Click here </a>
<a th:href="${website}" target="_blank"> Click here </a>
For example if the ${website} has the value www.example.com I get this result:
http://localhost:8081/MyApp/www.example.com
but I would like to get only this www.example.com without context Path.
I resolved it so:
<th:block th:with="link=${website}">
<a th:href="#{//{link}(link=${link})}" target="_blank">> Click here</a>
</th:block>
If you are linking to an external site, you should have http:// or https:// as part of the link -- https://www.example.com rather than just www.example.com. once you've added that, either of the two solutions in your initial post will work.
<a th:href="#{${website}}" target="_blank">Click here</a>
<a th:href="${website}" target="_blank">Click here</a>
// as you've indicated will work as well, but it's a bit silly. That just means that if your site is https:// it the link will be https:// (and vice versa for http://).
If you don't want to add https:// to your link, I would recommend something like this:
<a th:href="|https://${website}|" target="_blank">> Click here</a>
You can use dynamically, it works to me
<img th:src="${#httpServletRequest.scheme}+'://'+${#httpServletRequest.serverName}+':'+${#httpServletRequest.serverPort}+#{/user/display/${user.id}}" />
Related
I can't find a question similar to mine or I don't know the exact keywords to search for. I'm trying to get a link to look like this:
https://localhost/Index#about
however, i'm not sure where to insert the #about in the url parameters.
<a class="nav-link" asp-area="" asp-controller="Home" asp-action="Index">About</a>
If you're wondering, I'm using this piece of code for my navbar URLs. Thanks in advance!
Ok after searching the documentation of Microsoft:
<a class="nav-link" asp-area="" asp-controller="Home" asp-action="Index" asp-fragment="about">About</a>
The asp-fragment attribute defines a URL fragment to append to the
URL. The Anchor Tag Helper adds the hash character (#).
Source: https://learn.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/built-in/anchor-tag-helper?view=aspnetcore-3.0
Try this:
<a asp-action="Index" asp-controller="Home" asp-route-id="#about">Index</a>
Found this from Here
i have two href link to redirect page to new tab.
<a href="​http://www.sms.infisms.co.in/" target="_blank" >www.sms.infisms.co.in</a>
<br />
<a href="http://www.infisms.com" target="_blank" >www.infisms.com</a>
here first link redirect with this form http://localhost:3283/BulkSMSAdminProject/%E2%80%8Bhttp://www.sms.infisms.co.in/
what going wrong here..please help me..
I am trying to link an external link to the code.
Currently I have the following:
<div class="col-md-4">
<div class="thumbnail">
<a href="www.google.com" target="_blank">
<img src="/assets/laptop.jpg" alt="Fjords" style="width:100%">
<div class="caption">
<p>How to set up emails</p>
</div>
</a>
</div>
</div>
I am getting an error telling me "No route matches [GET] "/www.google.com". However, I only want to click onto the picture and for the page to go to google.
You need to specify the protocol too (https:)
<a href="https://www.google.com" target="_blank">
Relative URL (URL with no protocol specified) are used to reference links on the same site. You need to use the Absolute URL (with protocol and other information like protocol, domain name) to refer to an external site.
Relative URL are used to reference links on the same site. You need to use the Absolute URL to refer to an external site.
You can reference external links without protocol by:
<a href="//www.google.com" target="_blank">
Or use:
<a href="https://www.google.com" target="_blank">
I'm using Materialize Tabs and have everything working fine, except the fact that my URL doesn't update when I click a tab link. I have the following two links:
<ul id="db-tabs" class="tabs">
<li class="tab col s3"><a class="tab-text active" href="#activegroups">Active Groups</a></li>
<li class="tab col s3"><a class="tab-text" href="#submittedgroups">Submitted Groups</a></li>
</ul>
Yet when I click one of these links, the URL remains unchanged. I would have expected the URL to change to something like /admin#submittedgroups, yet is just remains /admin.
If I manually enter the url /admin#submittedgroups, i'll get taken to the correct tab but otherwise the URL never changes.
Any ideas of what i'm doing wrong?
The javascript library you're using is preventing the default action, including the default browser navigation. You'll need to manually update the URL with javascript if this is your desired behavior, or use a different library.
Whatever I set data-url or data-text to, twitter just fetches the URL of the page the sharing button exists in and shows as the tweet-text.
example :
<a target="_blank" href="https://twitter.com/share"
data-count="none" class="twitter-share-button" data-url="http://www.gogole.com"
data-text="BLABLABLA" style="opacity:0">TWEET</a>
or
<a target="_blank" href="https://twitter.com/share"
data-count="none" class="twitter-share-button" data-url="<?php echo
urlencode('http://www.gogole.com')?>" data-text="BLABLABLA" style="opacity:0">TWEET</a>
in both cases, clicking on the link opens a new window with the twitter sharing box that includes the URL of my website and ignores the attributes I set.
Something should have gone dangly wrong. help appreciated !
please tell me if you need more info to be posted.
Thanks,
/t
You can use the query parameter "url" with the twitter share link "https://twitter.com/share"
When looking for the URL twitter button follow this priority:
Look for url in the share link query string
If not found, look for the data-url attribute of the Tweet Button anchor tag
If not found, look for the rel="canonical" link tag in the head of the document
If not found use the URL of the webpage
I have faced same issue - when using link as described in manual's example it didnt work.
this NOT works:
<a class="twitterBtn smGlobalBtn" target=_blank href="https://twitter.com/share" data-text="my_title" data-url="my_url" data-hashtags="my_hash" data-via="my_name" data-related="my_name">Tweet</a>
but this WORKS:
<a class="twitterBtn smGlobalBtn" target=_blank href="https://twitter.com/share?text=my_text&url=my_url&hashtags=my_hash&via=my_name&related=my_name">Tweet</a>
Don't know why twitter ignores data- attributes, but when params are inside the link as GET params - everything works fine.
Hope this will be helpful for someone in future)
I fixed this by moving script widgets.js before button markup and turning off async mode, like this:
<script src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
<a href="https://twitter.com/share?ref_src=twsrc%5Etfw" class="twitter-share-button" data-text="H..." />
twitter-share-button class also important.