wood burning stoves 2.0
The moose likes HTML, CSS and JavaScript and the fly likes Changing cursors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Changing cursors" Watch "Changing cursors" New topic

Changing cursors

Mark JM Taylor

Joined: Apr 21, 2006
Posts: 6

I'm trying to write some code that will change the mouse pointer from one custom cursor to another depending on what the user's doing. I know that custom cursors in browsers are a (relatively) new concept, but both IE6 and Firefox 1.5.x and above should be able to handle them, right?

OK, here's my example in action:


Outside the box the cursor should be white (default), and inside it should be green. Then when the user clicks inside the box it should go blue then green again when the mouse is released.

But in IE6 this only works for the first click before it falls over. And in FF it does not work at all.

Here's the simple code:


<style type="text/css">

border: 1px solid #333333;

<script language="Javascript">

function cursor1()
div1.style.cursor = "url('green.cur')";
window.status = "up";

function cursor2()
div1.style.cursor = "url('blue.cur')";
window.status = "down";



<div class="table_borders" name="div1" id="div1" style="cursor:url('green.cur'); width:400px;height:400px;" onMouseDown="cursor2();" onMouseUp="cursor1();">
click in here


And a link to my two cursors to test it with:



Any thoughts, chaps?

Many thanks in advance.

Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
I would do something like this:

Now the thing is the onmousedown requires you to move the cursor for it to change. Also there is a slight delay for the image download.

Mark JM Taylor

Joined: Apr 21, 2006
Posts: 6
Hmmmm, yes, I see what you mean. I wonder if there's any way of forcing the cursor to refresh without moving the mouse.

It seems the implementation for custom cursors is almost an afterthought. And running the code in Firefox just gives 'Error in parsing value for property 'cursor'. Declaration dropped.'
I agree. Here's the link: http://aspose.com/file-tools
subject: Changing cursors
It's not a secret anymore!