views:

247

answers:

4

I have some CSS code that hides the cursor on a web page (it is a client facing static screen with no interaction). The code I use to do this is below:

*, html { cursor: url('/web/resources/graphics/blank.cur'), pointer; }

Blank.cur is a totally blank cursor file.

This code works perfectly well in all browsers when I host the web files on my local server but when I upload to a Windows CE webserver (our production unit) the cursor represents itself as a black box. Odd.

After some testing it seems that chrome only has a problem with totally blank cursor files when served from WinCE web server, so I created a blank cursor with one pixel as white, specifically for chrome. How do I then target this CSS rule to chrome specifically? i.e.

*, html { cursor: url('/web/resources/graphics/blank.cur'), pointer; }
<!--[if CHROME]>
*, html { cursor: url('/web/resources/graphics/blankChrome.cur'), pointer; }
<![endif]-->
+2  A: 

body:nth-of-type(1) { cursor: url('/web/resources/graphics/blank.cur'), pointer; } only for google chrome ;)

<script type="text/javascript">
if (/Chrome[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Chrome/x.x 
 var cversion=new Number(RegExp.$1);
 if (cversion>1)
    with(document) {
    //start the css
    write("<style type='text/css'>");
    write("html { cursor: url('/web/resources/graphics/blank.cur'), pointer; }");
    write("</style>");
  }
}
</script>

Based on Oli's comment.

neduddki
Nice idea, but will stop working once other browsers start implementing `nth-of-type`. Not a real option IMO.
Pekka
Yep, true. After the implement Oli's suggestion will be better.
neduddki
True Pekka but nice idea anyway marharepa
Chris
Workin fine :))
neduddki
+3  A: 

Chrome doesn't have any conditional comments like IE does.

My first idea was to use a bit of Javascript to very quickly look at the useragent string and then apply the style with javascript again. If you're already using jQuery, this would be pretty simple.

Oli
Would you mind helping me out with some code for that?
Chris
This would be problematic when JS is disabled. But that's not very likely for Chrome, so I guess it'd work ;)
August Lilleaas
+1  A: 

When I had a similar issue, I performed this check server side. The only way I could find was to sniff the user agent. Here from a Rails view.

<% if request.env["HTTP_USER_AGENT"] =~ /chrome/i %>
  <%= stylesheet_link_tag "chrome" %>
<% end>
August Lilleaas
Can this be done in ASP (not .NET)?
Chris
I ended up using a method very similar to this but in ASP.
Chris
+2  A: 

Turn the CSS around, targeting IE instead:

*, html { cursor: url('/web/resources/graphics/blankChrome.cur'), pointer; }
<!--[if IE]>
*, html { cursor: url('/web/resources/graphics/blank.cur'), pointer; }
<![endif]-->

Also, according to https://developer.mozilla.org/en/Using_URL_values_for_the_cursor_property Firefox and Safari (and presumably Chrome) supports GIFs for cursors, so you can try using a 1px transparent GIF.

Jeffery To