Forum Moderators: open

Message Too Old, No Replies

Safari scrollIntoView

         

fataqui

3:32 am on Feb 11, 2007 (gmt 0)

10+ Year Member



I don't have Safari and I am getting users telling me that my scroll method does not work in Safari. Is there a special method that Safari supports. I am opening a iframe and writing to it, then after closing it, I scroll to a <div> I just wrote to the iframe document!

This is what I'm using now, it seem to work for everything but Safari, but some people say they don't have trouble with Safari, so I am lost as what I need to add to be sure I get safari generically supported.


/* ... */

txt = "<html>\r\n";
txt += "<head>\r\n";
txt += "<style>\r\n";
txt += "body { background-color : #ffffff; font-family : arial, helvetica, sans-serif; margin : 0px; padding : 4px }\r\n";
txt += ".nsw, .swe { font-size : 12px }\r\n";
txt += ".nsw { color : #252525 }\r\n";
txt += ".swe { color : #fa6105; border : 1px solid #91d591; padding-left : 2px; padding-right : 2px; background : #e7f4e7 }\r\n";
txt += "</style>\r\n";
txt += "</head>\r\n";
txt += "<body>\r\n";
txt += "<div class='nsw'>" + scd + "<span id='highlight' class='swe'>" + scb + "</span>" + sce + "<br /></div>\r\n";
txt += "</body>\r\n";
txt += "</html>\r\n";
spell.document.open();
spell.document.write(txt);
spell.document.close();

/* try different methods to scroll to the highlight div */

// this where the problem is!

try
{
spell.document.getElementById('highlight').scrollIntoView();
}
catch(e)
{
try
{
spell.scroll(0, spell.document.getElementById('highlight').offsetTop);
}
catch(e)
{
try
{
spell.scrollTo(0, spell.document.getElementById('highlight').offsetTop);
}
catch(e)
{
alert(e.description);
}
}
}

TIA

sd!

mrhoo

6:46 pm on Feb 13, 2007 (gmt 0)

10+ Year Member



This function will use scrollIntoView if available, otherwise it calculates the page's distance to the top of the element and scrolls the page:
function goWin(hoo){
try{
hoo.scrollIntoView(true);
}
catch(er){
var T= 0;
var pa= who;
while(pa.parentNode){
T+= (pa.offsetTop)? pa.offsetTop: 0;
if(pa== document.body) break;
pa= pa.parentNode;
}
window.scrollTo(0,T);
window.scrollTo(0,vy);
}
if(vc===true){
try{
hoo.focus();
}
catch(er){
return true
}
}
}