Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

is there something faster than onload="parent.window.scrollTo(0,0); "&

Status
Not open for further replies.

fpl9250

Programmer
Jan 22, 2007
46
US
Hello,

I have an i-frame in which I made the height 1600px to avoid two scroll bars. I'm scrolling new pages to the top via parent.window.scrollTo(0,0), but the client is complaining that it is too slow. The whole page has to load and then the it's scrolled to the top. Is there a faster way? Is there something I can do to make it faster?

Thank you
 
I think you can look at the title of your thread for your answer:
[!]onload[/!]="parent.window.scrollTo(0,0); "

If you're using the onload handler to call the function then naturally it's going to wait for the page to load before the function does it's thing.

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson
 
I'm aware of that. So how do I fix it? Can I do something other than onLoad?
 
You can put the script directly into the HTML, but that can cause problems if things have not finished rendering first. For example, if you try to change the scrollTo on a scrolling <div> before the <div> has been drawn to the screen then you will get an error.

But, if you want to try it out in your code try putting something like this in the head of the page:
Code:
<script type="text/javascript">
parent.window.scrollTo(0,0);
</script>

That code will not wait for the page to load before it runs, as soon as the parser hits that line as the page is being "compiled" it will run immediately (so you'll likely want to put it near the top, as I mentioned above - in the <head> would be preferred)

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson
 
unfortunatelly I do NOT have access to the page that the i-frame loads so I cannot put it in the head of that page. Even if I could how would I triger the call to the scrollTo parameter if it's onLoad?
 
Even if I could how would I triger the call to the scrollTo parameter if it's onLoad?

I don't understand your question. My solution did not use the onload handler. Please be more specific.

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson
 
I don't understand why the content in the iframe isn't initially loading at the top of the page anyway.

[monkey][snake] <.
 
the page isn't loading to the top because the only visible scroll bar is the one for the parent window. Once they scroll all the way to the bottom and click continue the parent window stays scrolled down, but the i-frame doesn't scroll to the top
 
I would think kaht's solution should work. But if for some reason it is still too slow, you could try putting this in the head of your iframe page:
Code:
<script type="text/javascript">
parent.location.href='#';
</script>

Adam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top