Hi..
I'm having a problem of redirect my website to use another style sheets for ie and chrome.

This is the way i've done for ie detection :

<!--[if IE 8]>
      <link rel="stylesheet" type="text/css" href="css/ie8.css" />
      <! [endif] -->

and this is the way i've done for chrome detection :

<script type="text/javascript">
      if (navigator.userAgent.toLowerCase().match('chrome')
      document.write('<link rel="stylesheet" type="text/css" href="css/stylechr.css">');
      </script>

but the problem is none of these are working,and i'm in trouble now of fixing the stylesheet for these two browser.
please help,i really dont know what else to do.

Thank You :)

Dani AI

Generated

A quick diagnosis and a compact troubleshooting plan based on the thread: the IE issues are usually caused by malformed conditional-comment syntax or using a technique that IE no longer supports; Chrome problems commonly come from (a) invalid link attributes (nonstandard type), (b) JavaScript syntax errors that abort script execution, (c) wrong/relative paths that resolve differently under an IP vs localhost, (d) caching, or (e) the stylesheet being served with the wrong Content-Type or encoding. 's notes about correct placement (inside <head>) and paths are on point, and 's WordPress-path reminder is relevant when a CMS builds URLs.

Checklist (execute in order):

  1. Inspect Chrome DevTools → Network: confirm the browser requests the CSS and that it returns 200 with Content-Type: text/css.
  2. Verify the link tag uses a correct rel/type (omit nonstandard types) and is inside the document head. Prefer root‑relative or absolute paths (leading slash or full URL) if pages live at different depths.
  3. Look at the Console for JavaScript errors — a missing parenthesis in an if() will stop script execution and prevent any injected link from appearing.
  4. Hard-refresh or disable cache in DevTools while testing.
  5. If using @charset, save the file as UTF-8 without BOM and ensure @charset (if present) is the very first line.
  6. If the site behaves differently via IP vs localhost, check base URL / config.php settings and any server rewrite/virtual‑host differences.

Safer way to add a browser-specific stylesheet (avoid document.write and nonstandard type):

(function(){
  var ua = navigator.userAgent;
  if (ua.indexOf('Chrome') !== -1 && ua.indexOf('Edge') === -1 && ua.indexOf('OPR') === -1) {
    var l = document.createElement('link');
    l.rel = 'stylesheet';
    l.href = '/css/chrome-fixes.css';
    document.head.appendChild(l);
  }
})();

Longer-term: prefer feature detection (@supports) or progressive enhancement rather than browser sniffing; conditional comments only work up through IE9, so for modern browsers rely on capability checks rather than user-agent tests.

Recommended Answers

All 11 Replies

Try this for IE 8

<!--[if gt IE 7]>
	<link rel="stylesheet" type="text/css" href="css/ie8.css" />
<![endif]-->

AND TRY THIS FOR CHROME

<link rel="stylesheet" href="css/stylechr.css" type="text/chrome" />

Try this for IE 8

<!--[if gt IE 7]>
	<link rel="stylesheet" type="text/css" href="css/ie8.css" />
<![endif]-->

AND TRY THIS FOR CHROME

<link rel="stylesheet" href="css/stylechr.css" type="text/chrome" />

i dont know why...but it is still not working :( help2,please....

Did you link the style sheets correctly? css/ie8.css means that the folder css must be in the same directory as your site, and the file ie8.css must be in the css folder. Same with the chrome one.

yes..i already put it on the right directory and folder.
and this is a new thing that i realised,
when i open my website on the LAN address,i mean like :

my website appear correctly..

but when i open it up using the localhost address which is :
http://localhost/ ,my website appear wrongly.

how could this is being so?now i dont know,wheter the redirection code is not working or something else..
really make me confuse right now..

Your website will appear correctly at the path you defined in your config.php file. If localhost is not defined, it cannot appear there.

As for your original problem:

If you say it appears correctly on your LAN, do you mean in all browsers now, or only in some?

Your website will appear correctly at the path you defined in your config.php file. If localhost is not defined, it cannot appear there.

As for your original problem:

If you say it appears correctly on your LAN, do you mean in all browsers now, or only in some?

nope..by using LAN, it only appear correctly on mozilla and ie only,but not for chrome..

OK, so your IE problem is now sorted out, I gather.

For Chrome, try the full path to the stylesheet and see what happens.

<link rel="stylesheet" href="" type="text/chrome" />

Also, make sure the code for stylesheet is in the <head></head> section of your file.

Also make sure stylesheet starts with:

The first characters in the css-file should be:

@charset “UTF-8″;

OK, so your IE problem is now sorted out, I gather.

For Chrome, try the full path to the stylesheet and see what happens.

<link rel="stylesheet" href="" type="text/chrome" />

Also, make sure the code for stylesheet is in the <head></head> section of your file.

Also make sure stylesheet starts with:

The first characters in the css-file should be:

@charset “UTF-8″;

I cannot save the css file with @charset “UTF-8″;
a message pops up said that "it may contain chars that cannot be represented in current encoding."

ok, did you define the exact path now? You may also want to test what happens if you remove the doc type from the html tag at beginning of your file.

If not resolved, please post your chrome style sheet css code, and your index.php html here.

Make Sure that ur Link in the href is placed right. Check my code below if ur using a wordpress CMS :

<script type="text/javascript">
if (navigator.userAgent.toLowerCase().match('chrome'))
document.write('<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_directory'); ?>/css/stylechr.css" />')
</script>
<link rel="stylesheet" href="css/stylechr.css" type="text/chrome" />

works fine with me , thanx guys

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.