PDA

View Full Version : OnClick handler only partially working in Safari.


lazerbrains
10-10-2006, 06:54 PM
I have a page that has anchors in it and when you click on a link the page will scroll to an anchor. Everything works great in Firefox and IE, but Safari tends to only want to scroll up??!?!

See this example, this is the code I used to do this:

http://www.huntingground.freeserve.co.uk/main/mainfram.htm?../webplus/iframes/iframe_anchor_scroll.htm


I was wondering if anyone knows why or how to get Safari to correctly use an onClick event handler? Here is what I have and what is happening.

I have a link that is coded as follows:

<a href="#null" class="white" onClick="parent.scrollWin('anchor2')">Overview </a>

In Firefox and IE, the page scrolls down to 'anchor2'. In Safari it does nothing.

I also have code that you can click on to go back to the top:

<a href="#null" class="brown" onClick="parent.scrollWin('anchor1')">Back to top of page.</a>

Pretty much exactly the same, and again it works great in Firefox and IE, and oddly enough it does work in Safari as well.

I am not sure why, but it seems that the onClick will work if moving up the page, but not down?

Anyone have any info on this? Here is an example that I used to build this, let me know fi anyone can help.

Thanks :)

Kravvitz
10-11-2006, 10:13 PM
Why are you using JavaScript for that?

Where is scrollWin defined?

lazerbrains
10-11-2006, 10:17 PM
How would you do it without Javascript? scrollWin is defined on the main page. Then everything else is in the iFrame content. Did you take a look at the example I posted?

Kravvitz
10-11-2006, 10:29 PM
I had JavaScript disabled the first time I followed you link, so the page loaded in the iframe was the default one.

Please fix your X/HTML (http://validator.w3.org/check?verbose=1&uri=http%3A%2F%2Fwww.huntingground.freeserve.co.uk%2Fmain%2Fmainfram.htm%3F..%2Fwebplus%2Fiframes%2F iframe_anchor_scroll.htm) and CSS (http://jigsaw.w3.org/css-validator/validator?profile=css2&warning=2&uri=http%3A%2F%2Fwww.huntingground.freeserve.co.uk%2Fmain%2Fmainfram.htm%3F..%2Fwebplus%2Fiframes%2F iframe_anchor_scroll.htm) errors.

Try this.
<a href="#anchor2" target="myiframe" class="white" onclick="parent.scrollWin('anchor2');return false;">Overview </a>
I suggest you read these:
The Behavior Layer (http://www.digital-web.com/articles/the_behavior_layer/)
Separating behavior and structure (http://www.digital-web.com/articles/separating_behavior_and_structure_2/)
Behavioral Separation (http://www.alistapart.com/articles/behavioralseparation/)
Unobtrusive JavaScript (http://www.onlinetools.org/articles/unobtrusivejavascript/)
DOM Scripting - Sample chapter: Best Practices (http://www.domscripting.com/book/sample/)
Accessible DHTML (http://www.severnsolutions.co.uk/articles/001/)