The following is used to set the favicon in my html code:
<link rel="icon" type="img/ico" href="img/favicon.ico">
However, the icon does not show. Why?
Note:
I have confirmed that the file is on-disk at the correct path.
Is it really a .ico, or is it just named ".ico"?
What browser are you testing in?
The absolutely easiest way to have a favicon is to place an icon called "favicon.ico" in the root folder. That just works everywhere, no code needed at all.
If you must have it in a subdirectory, use:
<link rel="shortcut icon" href="/img/favicon.ico" />
Note the / before img to ensure it is anchored to the root folder.
Try this:
<link href="img/favicon.ico" rel="shortcut icon" type="image/x-icon" />
Favicons only work when served from a web-server which sets mime-types correctly for served content. Loading from a local file might not work in chromium. Loading from an incorrectly configured web-server will not work.
Web-servers such as lighthttpd must be configured manually to set the mime type correctly.
Because of the likelihood that mimetype assignment will not work in all environments, I would suggest you use an inline base64 encoded ico file instead. This will load faster as well, as it reduces the number of http requests sent to the server.
On POSIX based systems you can base64 encode a file with the base64 command.
To create a base64 encoded ico line use the command:
$ base64 favicon.ico --wrap 0
And insert the output into the line:
<link href="data:image/x-icon;base64,HERE" rel="icon" type="image/x-icon" />
Replacing the word HERE like so:
<link href="data:image/x-icon;base64,AAABAAEAEBAQAAEABAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAgAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAA////AERpOgA5cCcA7vDtAF6jSABllFcAuuCvAK2trQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFjMzMzMzNxARYzMzMzVBEEERYzMzNhERZxRGMzZxQEA2FER3cRSAgTNxgEEREIQBMzFIARERFEEzNhERARFAATMzYREBEAhBMzMzEYEBFEEzMzNhEQQRQDMzMzcRgEAAMzMzNhERgIEzMzMyERgEQDMzMzMRAEgEMzMzMxERAEEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" rel="icon" type="image/x-icon" />
Try adding the profile attribute to your head tag and use "image/x-icon" for the type attribute:
<head profile="http://www.w3.org/2005/10/profile">
<link rel="icon" type="image/x-icon" href="img/favicon.ico">
If the above code doesn't work, try using the full icon path for the href attribute:
<head profile="http://www.w3.org/2005/10/profile">
<link rel="icon" type="image/x-icon" href="http://example.com/img/favicon.ico">
Related
I am having issue with loading static files in spring mvc. I have in my java config something like this:
#Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
When I deploy my app and visit it in browser
http://localhost:8080/MyApp/
No CSS is loaded. When I go to source I see that path is something like this:
http://localhost:8080/resources/css/style.css
Which is incorrect. If I change it to:
http://localhost:8080/MyApp/resources/css/style.css
Then I can see my css file. What am I doing wrong?
In my css I am linking to resources like this:
<link href="/resources/css/style.css" rel="stylesheet" type="text/css" />
Thanks for help.
When specifying a path like
<link href="/resources/css/style.css" rel="stylesheet" type="text/css" />
where the path is prefixed with /, the browser appends that path to the your host, not to your application context. For example, say you made your first request to
http://localhost:8080/MyApp/
then your browser would try to get the css at
http://localhost:8080/resources/css/style.css
as you've noticed. If you don't put a / at the front of the path like
<link href="resources/css/style.css" rel="stylesheet" type="text/css" />
then the browser will use the current location URL as the base.
http://localhost:8080/MyApp/resources/css/style.css
But if the current URL was
http://localhost:8080/MyApp/some/other/path
then the same path css <link> would be resolved to
http://localhost:8080/MyApp/some/other/path/resources/css/style.css
which is not what you want.
You want to css link to always be resolved on your application's context path. You can do this with the JSTL core taglib like so
<link href="<c:url value="/resources/css/style.css" />" rel="stylesheet" type="text/css" />
or with EL as
<link href="${pageContext.request.contextPath}/resources/css/style.css" rel="stylesheet" type="text/css" />
A leading slash in a URL makes it relative to the Host, in your case http://localhost:8080/. So to be relative to the current URL leave it out.
You can also use <c:url > which makes the address relative to the servlet address, no matter what the current URL is.
<link href="<c:url value="/resources/css/style.css"/>" rel="stylesheet" type="text/css" />
This way, even if you have opened the page http://localhost:8080/MyApp/whatever/, the stylesheet will have the correct URL.
I'm aware this is similar to numerous existing posts but after looking at a number of others I wasn't able to solve my problem. I'm attempting to load a folder full of html files I've been supplied with. I didn't write them but I have been modifying them to integrate them into an existing system.
I've tried three ways of opening them, with varying success:
1) Simply right click on 'index.html' and go 'open with' and select a browser. This works perfectly!
2) Place the whole folder contents, unchanged, onto my server under 'public_html/cat/html' and navigating to the url 'localhost/cat/html/index.html'. This returns a '404 page not found error'.
3) The strange one. Place the html files in the 'application/view' folder, separate the included css and javascript files and place them in existing folders 'public_html/css' and 'public_html/js' and update the links to them in the html files appropriately. These now look something like:
<link type="text/css" href="css/cat/style.css" rel="stylesheet" />
If I load this page by running a function that uses CodeIgniter's $this->load->view(...) function it finds the index file but loads it with no css and with broken links to the other pages. I've explored the page source and seen that the link is exactly as above but clicking gives an error that reads "404 Not Found...The requested URL /css/cat/style.css was not found on this server".
I've attempted to use the base_url() function (and site_url()) like this:
<link type="text/css" href="<? base_url('css/cat/style.css') ?>" rel="stylesheet" />
and it yields the same result on the surface but examining the page source reveals the link line has become:
<link type="text/css" href="" rel="stylesheet" />
which seems to be even worse!
Any hints?
Thanks for reading
Try the following:
<link type="text/css" href="<?php echo base_url('css/cat/style.css') ?>" rel="stylesheet" />
base_url() functon simply return value, you should take a care for displaying returned value to output! :-)
Have you correctly configure you config file in codeIgniter ?
Or shorthand
<link type="text/css" href="<?=base_url('css/cat/style.css') ?>" rel="stylesheet" />
Then view your page source and copy the link from there to your browser, see if you can access it.
Can try this code <link type="text/css" href="<?=base_url('css/cat/style.css');?>" rel="stylesheet" />
if it doesn't work, you could try <link type="text/css" href="<?=base_url('css/cat');?>/style.css" rel="stylesheet" />
I want to extract the title image of a web page using C# in ASP.NET. I checked the windows and document objects but they don't have a property such as title. So searching for method to extract the title image like in the page tab of the Chrome.
using (WebClient client = new WebClient())
{
Byte[] favico = client.DownloadData("http://msite.com/favico.ico");
}
That's using WebClient.DownloadData. You can also use WebClient.DownloadFile if you're looking to store it.
A further bullet-proofed approach would be to download the index page and use an HTML parser to look for the <link> tag that specifies where the icon is supposed to be (could also be applied to apple-touch-icon or otherwise).
BTW, the tags I believe you're looking to parse are:
<!-- StackOverflow's implementation: -->
<link rel="shortcut icon" href="http://cdn.../favicon.ico">
<link rel="apple-touch-icon" href="http://cdn.../apple-touch-icon.png">
<!-- Google's implementation: -->
<meta content="/images/google_favicon_128.png" itemprop="image">
<!-- Facebook's implementation: -->
<link href="http://static.ak.fbcdn.net/.../q9U99v3_saj.ico" rel="shortcut icon">
There is no such a thing as "title image" in HTML specifications. The icon you see in the tab or near the URL in some browser is specified using <link rel="icon"/> construct:
<link type="image/x-icon" href="/images/favicon.ico" rel="icon" />
IE may rquire you to use a slightly different syntax:
<link type="image/x-icon" href="/images/favicon.ico" rel="shortcut" />
Parse the page - and retrieve the value of href attribute - this is the path of the icon.
Note also, that IE version 8 and below ignore this line completely and instead look for file favicon.ico in the root of the site. See this somewhat old article for more information on IE.
In my .net application i have Styleshet.css in CSS folder.
Now i want to link this css in Sample.aspx.
What would be the best approach
1.
<link href="CSS/StyleSheet.css" rel="Stylesheet" type="text/css" />
OR
2.
<link href="<%=ConfigurationManager.AppSettings["ApplicationUrl"].ToString()%>/CSS/StyleSheet.css" rel="Stylesheet" type="text/css" />
In Web.Config
<appSettings>
<add key="ApplicationUrl" value="http://localhost/myapp/" />
</appSettings>
The best way in asp.net is option 3:
<link href="~/CSS/StyleSheet.css" rel="Stylesheet" type="text/css" />
The ~/ resolves to the site path root. The difference between this and just "css/... is that it will work no matter what subfolder you're in. For example if your code was in
/subsection/default.aspx
and your styles were in folder /css
using a link to "css/stylesheet.css" would resolve (incorrectly) to "/subsection/css/stylesheet.css" whereas using "~/css/stylesheet.css" would resolve (correctly) to "/css/stylesheet.css"
This also differs from a hard path root "/css/stylesheet.css" in that it will work correctly regardless of the virtual directory configuration of the site.
<link href="CSS/StyleSheet.css" rel="Stylesheet" type="text/css" />
Dont go for second approach as when you deploy your site to a server the /localhost/ reference wont work.
Well, always use relative paths so that you don't have to change your files after the deployment.
You can also use resolved app relative path such as
<link href="<%= ResolveUrl("~/CSS/StyleSheet.css") %> rel="Stylesheet" type="text/css" />
Reletive path approch is much better (your first approch), Absolute paths are not portable between applications. If you move the application that the absolute path points to, the links will break.
You can find more information on below mentioned link
Specifying Paths for Resources
In my application I have next problem. I created master page and some content pages, some of which are located in the nested folders. In the master page I added the link to .css file
<link href="default.css" rel="stylesheet" type="text/css" />
But pages are located in the nested folders can't use this .css file. How can I fix this? I want to have one .css file for all pages (:
Thanks!
<link href="~/default.css" rel="stylesheet" type="text/css" />
This problem can be resolved by adding next code in master page
<style type="text/css" runat="server">
#import '<%= ResolveUrl("~/default.css")%>';
</style>
But designer of VS can't process this and you couldn't view your styles in it.
The css shouldnt be relative to the master page but rather it should be relative to the location of the Page instance using the master page. In most cases this will be the same thing but I would always try to use either a fully qualified path or a site relative path
Fully qualified path
<link href="http://some.site.com/mysite/styles/default.css" rel="stylesheet" type="text/css" />
or a relative path (note this might not work if you have a version which can only host one site but many apps such as WinXP)
<link href="/default.css" rel="stylesheet" type="text/css" />
Win xp relative path
<link href="/path/to/application/default.css" rel="stylesheet" type="text/css" />
If you using website under website, change in subfolder masterpage CSS link
<link href="Styles/Site.css" rel="stylesheet" type="text/css" />
change with below
<link href="../Styles/Site.css" rel="stylesheet" type="text/css" />
The way you defined you style sheet means: the style sheet is in the same folder as the page which uses it.
If you want to have one style sheet for all pages you should put in in one place (I prefer /assets/css folder in the application root) and define the path using this folder:
<link href="/assets/css/default.css" rel="stylesheet" type="text/css" />
The other way to archieve this is to use Themes, in this case styles will be added automatically.