Thomas’ Developer Blog

October 16, 2008

Imposing functions onto document.body.onmousemove

My last post went over how to handle onscroll with window.onscroll and adding an additional function to an existing function. Well with document.body.onmousemove there is a bit of a problem with Firefox.

In order for the script to work you need to determine if a value already exists. This is where the problem lies with FF. To get the value, the only way to do it that I know works is…

if (document.body.getAttribute("onmousemove")) { }

Once you have that going you can simply do the same but… but it requires a bit more work sadly.

As with the previous example in the last post, with onscroll, you always need to have it referenced as

function() { /* your code */ }

In IE and most other browseres, besides FF, the returned code will always be treated as an anyomous function. Meaning when you call back document.body.onmousemove it is treated as a function which requires you to call…. document.body.onmousemove(), in FF it is returned as document.body.onmousemove without the () so the next part of this puzzle is to determine the browser type. In this case I tested for FF by using the following…

if (navigator.userAgent.indexOf("Firefox")!=-1) {
 //FF code
} else {
 //Non-FF code
}

The final result of combing these methods is:

if (document.body.getAttribute("onmousemove")) {
   var MouseMoveCode = eval(document.body.onmousemove);
   if (navigator.userAgent.indexOf("Firefox")!=-1) {
      var MouseMoveEvent = function(event) { 
         dragDiv(event,CustomControls.OverlayMenu.MouseMoveCode)};
         document.body.onmousemove = MouseMoveEvent;
   } else {                
      MouseMoveEvent = function(event) { 
      dragDiv(event,MouseMoveCode())};
      document.body.onmousemove = MouseMoveEvent;
   }
} else {
   document.body.onmousemove = function(event) { dragDiv(event) };
}
Advertisements

21 Comments »

  1. Hello webmaster
    I would like to share with you a link to your site
    write me here preonrelt@mail.ru

    Comment by Alexwebmaster — March 3, 2009 @ 11:22 am

  2. What a stuff of un-ambiguity and preserveness of valuable
    familiarity regarding unexpected feelings.

    Comment by how to configure best cable how to configure modem billion — August 12, 2014 @ 10:10 pm

  3. Hi there, just became alert to your blog through Google,
    and found that it’s truly informative. I’m gonna watch out for brussels.
    I’ll appreciate if you continue this in future. Numerous people will be benefited from your writing.
    Cheers!

    Comment by how to configure best cable best comcast modem for gaming — August 13, 2014 @ 3:08 am

  4. Heya! I’m at work surfing around your blog from my new iphone 3gs!
    Just wanted to say I love reading through your blog and look forward to
    all your posts! Carry on the superb work!

    Comment by how to configure best cable best cable modem for mac — August 24, 2014 @ 12:14 am

  5. I am not sure where you’re getting your info, but good
    topic. I needs to spend some time learning more or understanding more.
    Thanks for excellent info I was looking for this information for my mission.

    Comment by how to configure best comcast best how to connect xbox 360 — September 3, 2014 @ 7:41 am

  6. Amazing! Its truly amazing paragraph, I have got much clear idea regarding
    from this paragraph.

    Comment by how to configure arris best wireless cable modem — September 8, 2014 @ 6:35 am

  7. Hi there exceptional website! Does running a blog such as this require
    a massive amount work? I have very little expertise in coding
    however I had been hoping to start my own blog in the near future.
    Anyway, if you have any ideas or tips for new blog owners please share.
    I know this is off subject nevertheless I simply wanted to ask.
    Cheers!

    Comment by how to configure best best comcast how to configure modem — September 9, 2014 @ 12:20 pm

  8. Pretty! This was an incredibly wonderful post. Many thanks for supplying this information.

    Comment by how to configure best comcast best comcast modem for xbox — September 18, 2014 @ 8:01 am

  9. I’m impressed, I must say. Rarely do I come across a blog that’s both educative and interesting, and let me tell you, you’ve hit the nail on the head.
    The problem is something that too few people are speaking intelligently
    about. I’m very happy I stumbled across this in my search for something concerning
    this.

    Comment by how to configure best cable the the best modem for xbox — September 18, 2014 @ 5:58 pm

  10. Nice weblog right here! Also your web site a lot up fast!
    What web host are you using? Can I am getting your associate hyperlink to your host?
    I wish my web site loaded up as fast as yours lol

    Comment by 42 tv — September 19, 2014 @ 10:06 am

  11. Hi Dear, are you really visiting this site regularly,
    if so after that you will definitely obtain good know-how.

    Comment by how to configure best best wireless best cable modem for comcast — September 19, 2014 @ 4:51 pm

  12. Hi there colleagues, its wonderful paragraph on the topic of tutoringand completely explained, keep it up all the
    time.

    Comment by how to configure best best docsis 3 arris cable modem for comcast — September 20, 2014 @ 2:04 am

  13. Hurrah! At last I got a website from where I know how to
    really obtain useful information concerning my study
    and knowledge.

    Comment by how to configure best comcast dsl how to configure modem — September 20, 2014 @ 8:01 am

  14. Hello, its pleasant post concerning media print,
    we all be aware of media is a impressive source of information.

    Comment by how to configure best comcast best cable modem for time — September 20, 2014 @ 9:43 am

  15. Hmm is anyone else having problems with the pictures on this blog
    loading? I’m trying to find out if its a problem on my end or if it’s
    the blog. Any feed-back would be greatly appreciated.

    Comment by how to configure best best dsl best dsl modem for xbox — September 20, 2014 @ 10:45 am

  16. You really make it appear really easy with your presentation but I in finding this topic
    to be really something which I think I might by no means understand.
    It kind of feels too complex and very huge for me.
    I am looking forward in your subsequent publish, I’ll attempt to get the hang of it!

    Comment by how to configure best comcast cable modem for xbox 360 — September 21, 2014 @ 3:27 pm

  17. Hi there! Do you know if they make any plugins
    to help with Search Engine Optimization? I’m trying to get my blog to
    rank for some targeted keywords but I’m not seeing very good success.
    If you know of any please share. Cheers!

    Comment by how to configure best cable best best att dsl modem for — September 23, 2014 @ 12:51 am

  18. Hey, I think your blog might be having browser compatibility issues.
    When I look at your blog in Opera, it looks fine but when opening in Internet Explorer, it has some overlapping.
    I just wanted to give you a quick heads up! Other then that, awesome blog!

    Comment by how to configure best buy fastest cable modem for comcast — September 28, 2014 @ 4:26 am

  19. This is very interesting, You are a very skilled blogger.
    I’ve joined your rss feed and look forward to seeking more of your fantastic post.
    Also, I’ve shared your web site in my social networks!

    Comment by how to configure best cable modem for comcast internet — September 30, 2014 @ 9:23 pm

  20. Pretty nice post. I simply stumbled upon your weblog and wanted
    to say that I have really loved surfing around your blog posts.
    In any case I’ll be subscribing for your rss feed
    and I am hoping you write once more soon!

    Comment by Hobie Kayaks — October 1, 2014 @ 6:03 am

  21. Hey there! I’m at work browsing your blog from my new iphone!
    Just wanted to say I love reading through your blog and look forward to all your posts!

    Keep up the superb work!

    Comment by Il mondo dell’archeologia — October 3, 2014 @ 2:02 am


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: