Scot Schlinger

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromScot Schlinger
ToMe
SubjectGreat site and question on broswer compatibility
Date22 September 2006 19:11
AttachmentSample script
Hi Mark,

Thank you for so much useful information on your site.  I am going to have
to spend a lot of time there over the next few weeks!

A friend sent me to your site link as I am trying to find out why certain
things are happening on my site.  I have just started working with
javascript (AJAX) in production (I have worked with it, but not at this
level or capacity).  I have a page (link below) when a user mouses over a
checkbox or label it will pop open a window and use ajax to grab the
appropriate information to display in a div.  At the current moment this
works exactly as expected in FF 1.x, IE 6.x , and Opera 9.x.  But, when I
scroll the page down a little in IE and Opera, the div that is created no
longer is attached to the cursor but drops to the bottom of the page.
I have been trying to figure this out for the past couple of days (my head
hurts :) ) and was wondering if you might be able to shed a little light on
my problem as I don't believe it is CSS related by javascript related.  The
script is one I found on the net and adapted to fit my needs and the portion
of it that I think might not be working as needed is the code just before
the "getmouseposition" method and that method itself.

Site: [URL]
JS: attached (the function in question is getmouseposition which is called
from method tooltip)

Thank you for your time and consideration,
Scot Schlinger
FromMe
ToScot Schlinger
SubjectRe: Great site and question on broswer compatibility
Date23 September 2006 13:46
Scot,

> JS: attached (the function in question is getmouseposition which is
> called from method tooltip)

This is your problem:
var ie5 = (document.getElementById && document.all);
var ns6 = (document.getElementById && !document.all);
var ua = navigator.userAgent.toLowerCase();
var isapple = (ua.indexOf('applewebkit') != -1 ? 1 : 0);

That sniffer is complete nonsense. Please remove it.

I have documented how to calculate the mouse position after a mouse event
here:
http://www.howtocreate.co.uk/tutorials/javascript/eventinfo
See the section called "Detecting the mouse coordinates when it moves over
a positioned element".

Hope this helps.


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromScot Schlinger
ToMe
SubjectRe: Great site and question on broswer compatibility
Date25 September 2006 15:21
Mark,

Thank you for your reply, it is appreciated.  I have looked at the link that
you sent, but now I am a little confused.  In order to make this script
work, don't I need some type of "sniffer?"  If so, should I use the one on
this page http://www.howtocreate.co.uk/tutorials/javascript/dhtml of your
site?

I know enough javascript to be dangerous and it usually takes me a while to
make stuff work.  Therefore I want to make sure I am barking up the correct
tree.

Regards,
Scot
FromMe
ToScot Schlinger
SubjectRe: Great site and question on broswer compatibility
Date25 September 2006 15:52
Scot,

> In order to make this script work, don't I need some type of "sniffer?"

Normally I would say "no, absolutely not". Most scripts should never, ever
use sniffers, and if you start out by relying on them, you are heading in
the wrong direction. Sniffers are generally a big pile of rubbish, asking
for trouble, since they make ridiculous and inaccurate assumptions about
browser capabilities (as you can see by the fact that yours is not working).
What you should do is detect a browser's _capabilities_ as use them
accordingly.

However, in the case of mouse position, it is a mess, and unfortunately
there are some (older) browsers that get it wrong. It is one of the only
places where a sniffer is actually needed, but it needs to be done carefully
so it uses a capability detect first, then detects only the browsers that
get it wrong, and fixes them, without harming the browsers that get it
right. That is what my script does.

As it happens the three browsers that got it wrong have all been replaced
with versions that get it right, so in theory the sniffer I use could
potentially be removed now (I only keep it for the few remaining users of
the older versions of those browsers).

> If so, should I use the one on this page
> http://www.howtocreate.co.uk/tutorials/javascript/dhtml of your site?

Yes. Use my script for getting the mouse position, not the one you are
currently using.

Something like this should work (I did a few quick tests with your page, and
it seemed to work just fine):

function getmouseposition(e) {
  if( !e ) { e = window.event; }
  if( !e || !document.getElementById ) { return; }
  var xcoord, ycoord;
  if( typeof( e.pageX ) == 'number' ) {
    xcoord = e.pageX; ycoord = e.pageY;
  } else if( typeof( e.clientX ) == 'number' ) {
    xcoord = e.clientX; ycoord = e.clientY;
    var badOldBrowser = (
     window.navigator.userAgent.indexOf( 'Opera' ) + 1 ) ||
     ( window.ScriptEngine && ScriptEngine().indexOf( 'InScript' ) + 1 )
     || ( navigator.vendor == 'KDE' );
    if( !badOldBrowser ) {
      if( document.body &&
        ( document.body.scrollLeft || document.body.scrollTop ) ) {
        xcoord += document.body.scrollLeft;
        ycoord += document.body.scrollTop;
      } else if( document.documentElement && (
        document.documentElement.scrollLeft ||
        document.documentElement.scrollTop ) ) {
        xcoord += document.documentElement.scrollLeft;
        ycoord += document.documentElement.scrollTop;
      }
    }
  } else { return; }
  global_kitID.style.left = (xcoord+offsetx) + 'px';
  global_kitID.style.top = (ycoord+offsety) + 'px';
}

But please, read the page where I explain how this script works, it will
help you to understand why I am doing what I do in this script.
FromScot Schlinger
ToMe
SubjectRe: Great site and question on broswer compatibility
Date25 September 2006 16:02
Mark,

Thank you for your quick reply.
I will have to try out the script and I will reread that section again.  I
have been reading a lot on your site and I think I am starting to spin as I
am trying to take on too much too fast.  Thank you for creating one of the
most useful sites I have been to in a long time!

Regards,
Scot
FromScot Schlinger
ToMe
Subjectquesiton on tabs
Date28 September 2006 17:10
Hi Mark,

You were recently kind enough to help me with a javascript issue dealing
with a mouse pointer problem and a call with AJAX so that when a person
moused over a form checkbox a box would open up.  It works beautifully and I
want to thank you again for your time and help.

Now I am onto another project, but I don't know if the scripts I have found
on the web are quite what I am looking for and/or if they are the best way
to do things.  Here is the one I am thinking of using: [URL] (demo here:
[URL]) but I think that this method is old.

Sorry for the rambling, I guess I am just looking for your input on a good
tab tutorial so I can learn the correct way to do it and your input on if
this is really a good idea?

Regards,
Scot
FromMe
ToScot Schlinger
SubjectRe: quesiton on tabs
Date28 September 2006 19:53
Scot,

> Now I am onto another project, but I don't know if the scripts I have
> found on the web are quite what I am looking for and/or if they are the
> best way to do things.

I generally do not like to make any recommendations about anyone else's
scripts. The one you were looking at works, and the markup it uses is not
too ugly. It is up to you to decide if it fits in with your site and your
needs.
FromScot Schlinger
ToMe
SubjectRe: quesiton on tabs
Date28 September 2006 19:50
Thank you for your reply.  I understand your position.

One last question;
style.border = '1px solid #000';  // works
style.borderBottom = '1px solid #000';  // doesn't work
style.borderBottomColor = '#000';  // doesn't work

Is this true for every browser?  I have tried to search the net and I have
found scripts that use the above, but they don't say it works.  I don't get
it?
FromMe
ToScot Schlinger
SubjectRe: quesiton on tabs
Date28 September 2006 19:57
Scot,

> Is this true for every browser?

Those should work in all browsers that support DOM:
http://www.howtocreate.co.uk/tutorials/javascript/domintroduction
FromScot Schlinger
ToMe
SubjectRe: quesiton on tabs
Date28 September 2006 20:03
Mark,

I have been playing around with it, but when I do:

document.getElementById('<id>').style.borderbottomcolor = '#fff';

I don't see any difference on the screen in ff 1.05 and ie 6.x.  If I add
the line directly after the above

alert(document.getElementById('<id>').style.borderbottomcolor);

it does spit out #fff but there is not change the element I am trying to
change.  Also, if I do the above line without the first line I receive
"undefined"???

Regards,
Scot
FromMe
ToScot Schlinger
SubjectRe: quesiton on tabs
Date28 September 2006 20:08
Scot,

> document.getElementById('<id>').style.borderbottomcolor = '#fff';

1. I assume you are not actually putting the < and > characters in.

2. As with everything in JavaScript, it is case sensitive. See what you
wrote in your last email, you got it right there :)

> I don't see any difference on the screen in ff 1.05 and ie 6.x.

Please include results for Opera in any future communication of this
kind.
FromScot Schlinger
ToMe
SubjectRe: quesiton on tabs
Date28 September 2006 20:16
AttachmentDemo page
Mark,

I appreciate your quick replies and help.

Based on your comment, I assuming I must use this:

document.getElementById('<id>').style.borderBottomColor = '#fff';

which I did try and it didn't work in any of the browsers (IE, FF, O).  I am
attaching my file (it is .php, but you can change to .html as there isn't
any php in it) as I can't figure out why this doesn't work?
FromMe
ToScot Schlinger
SubjectRe: quesiton on tabs
Date28 September 2006 21:14
Scot,

> document.getElementById('<id>').style.borderBottomColor = '#fff';

Yep. But...

You told it not to display the bottom border:
border-bottom: none;
The border that you see is produced by the box underneath it. So you are
changing the colour, but the size of the border is still none. Try this
instead:

document.getElementById('<id>').style.borderBottom = '1px solid #fff';

Note that you could simplify this:
<a href="javascript:showTips('link_1');" id="link_1"
  onmouseover="changeColor(document.getElementById('link_1'));">1 - 10</a>
To this:
<a href="javascript:showTips('link_1');" id="link_1"
  onmouseover="changeColor(this);">1 - 10</a>
Since it is inside the event handler for that element, the word 'this' is a
reference to the element itself.
FromScot Schlinger
ToMe
SubjectRe: quesiton on tabs
Date28 September 2006 21:23
Wow, I am really stupid!  2 hours of frustration solved by such a "little"
solution.  Thank you for your time and help they are greatly appreciated. 
You don't happen to have a book out, do you?  I ride the train for an hour
each way every day to work and could use some reading material :)
FromMe
ToScot Schlinger
SubjectRe: quesiton on tabs
Date28 September 2006 21:29
Scot,

> You don't happen to have a book out, do you?

By way of explanation;
http://www.howtocreate.co.uk/aboutsite.html#saveprint
FromScot Schlinger
ToMe
SubjectRe: quesiton on tabs
Date28 September 2006 21:36
Mark,

That makes more sense to me.  I will be checking back often for changes
while I try to learn in the process (and probably ask a few questions). 
Thank you for being more than hospitable with your time and advice.

Regards,
Scot
FromScot Schlinger
ToMe
SubjectRe: quesiton on tabs
Date28 September 2006 22:40
AttachmentDemo page
Hi Mark,

I have been working hard on my own tabs as I didn't seem to find anything I
like; I just hope they fit into my design without much change to the css or
blowing up completely.

You can see what I have so far: [URL] (I am attaching source to better help
with question)

I have one question about the following javascript function:

function changeBackgroundColor() {
   for(j = 1; j <= 5; j++) {
       document.getElementById('link_'+j).style.background = '#dde';
   }
}

In that function I am attempting to change the background of each tab to the
original state.  It is very forced at best.  Is there a way within that
unordered list that I can look at the selected id and turn them off more
"dynamically" in case I have to add, subtract, or change the id value of a
tab?

Thank you,
Scot
FromMe
ToScot Schlinger
SubjectRe: quesiton on tabs
Date29 September 2006 08:14
> Is there a way within that unordered list that I can look at the selected
> id and turn them off more "dynamically" in case I have to add, subtract,
> or change the id value of a tab?

Sure, just use a better condition in your 'for' loop than 'j <= 5'. Try
getting a reference to an element, and continue if it worked:

function changeBackgroundColor() {
 for( var j = 1, el; el = document.getElementById('link_'+j); j++ ) {
  el.style.background = '#dde';
 }
}

> I was wondering why my tabs cause the page to scroll back to the top
> if you scroll down the page and then click on a link?

Typically happens if you are using # as your link href, but forgetting to
return false in the onclick event handler.

In your case, you say this:
return showTips(...)
But showTips does not return any value, so you are returning undefined
instead of false. Put 'return false' at the end of your showTips
function.
FromScot Schlinger
ToMe
SubjectRe: quesiton on tabs
Date29 September 2006 23:13
Mark,

Once again, I have another question.  I know you are surprised.  I was
wondering why my tabs cause the page to scroll back to the top if you scroll
down the page and then click on a link?  I have seen others that dont' work
that way?  Is it something that I am missing?

Thank you,
Scot
FromScot Schlinger
ToMe
SubjectRe: quesiton on tabs
Date4 October 2006 23:13
Hi Mark,

I was looking on your site, but couldn't find the following on your site: if
javascript is enabled by the client or not.  I am going to be redoing my
baseball site and I want to know if they have it activated or not.  If not,
I want to disable and show a warning that they can't access an online quiz
without javascript enabled as I want to use tabs and/or ajax to run it.

Thank you,
Scot 
FromMe
ToScot Schlinger
SubjectRe: quesiton on tabs
Date5 October 2006 09:42
Scot,

> I was looking on your site, but couldn't find the following on your site:
> if javascript is enabled by the client or not.

http://www.howtocreate.co.uk/tutorials/javascript/incorporate
<noscript>
FromScot Schlinger
ToMe
SubjectRe: quesiton on tabs
Date5 October 2006 20:00
Mark,

That page didn't seem to have what I was looking for or am I missing it?

Thank you,
Scot
FromMe
ToScot Schlinger
SubjectRe: quesiton on tabs
Date6 October 2006 10:31
Scot,

The page has what you need. Just use the <noscript> tag, as shown on that
page. You can put your message in there, and it will show up if they have
JavaScript disabled.
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.