Forum Moderators: open

Message Too Old, No Replies

How do I correct a scrolling problem?

         

liwei

1:40 am on May 30, 2003 (gmt 0)

10+ Year Member



An undesired scrolling happened in my web page.

There is an anchor with every link in inframe window.

Click on a link, the line with the clicked link will be the top line in the inframe window. All lines outside of the inframe window would not move. This is the effect I need.

It works when all lines can been seen in one page (no need to use scroll bar).

It doesn't work well when a web page has more lines in it. After you click a link in the inframe window, this full page will scroll up, the lines above the inframe window can not been seen if you don't scroll down.

How to solve this problem?

[edited by: Marcia at 1:59 am (utc) on May 30, 2003]
[edit reason] No urls, please. [/edit]

MWpro

2:03 am on May 30, 2003 (gmt 0)

10+ Year Member



Read the charter/tos, posting url's is not permitted.

Even so, I immediately leave any page that prompts me to download chinese text.

From what you typed I am not really sure what your problem is. It is unclear to understand what you exactly mean.

Mardi_Gras

2:07 am on May 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I immediately leave any page that prompts me to download chinese text

Well, liwei is in China, so a little Chinese text on the website should not be unexpected ;)

Welcome to WebmasterWorld, liwei. Hopefully someone here will be able to help you with your scrolling problem.

liwei

3:29 am on May 30, 2003 (gmt 0)

10+ Year Member



Hi, my friends

I have sent you emails via StickyMail to describe my problems, you will find the URL to see the effect.

liwei

1:47 pm on May 31, 2003 (gmt 0)

10+ Year Member



An undesired scrolling happened in my web page.
There is an anchor with every link in iframe window.

Click on a link, the line with the clicked link will be the top line in the iframe window. All lines outside of the iframe window would not move. This is the effect I need.

It works when all lines can been seen in one page (no need to use scroll bar).

It doesn't work well when a web page has more lines in it. After you click a link in the iframe window, this full page will scroll up, the lines above the iframe window can not been seen if you don't scroll down.

How to solve this problem?

The following are three html files, run a.htm to see the effect.
**************************
a.htm

<html>

<head>
<title>gggggggggg</title>
</head>

<body>
a<br>
b<br>
c<br>
e<p>
<iframe name="I2" src="b.htm">do not support inframe</iframe>
iframe with b.htm in it.</p>
<p>
There is an anchor with every link in b.htm</p>
<p>
Click on a link, the line with the clicked link will be the top line in inframe
window. All lines outside of the iframe window would not move. This is the
effect I need.</p>
<p>
It works when all lines can been seen in one page (no need to use scroll bar),
please click <a href="c.htm">here</a> to see the effect.</p>
<p>
It doesn't work well when a web page has more lines in it, just like this page.
After you click a link in the iframe window, this full page will scroll up, the
line a,b,c,d can not been seen if you don't scroll down.
</p>
<p>
How to solve this problem?</p>
<p> </p>
<p>s</p>
<p>d</p>
<p>f</p>
<p>g</p>
<p>h</p>
<p>i</p>
<p>j</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>

</body>

</html>
*************************
b.htm

<html>

<head>
<title>1</title>
</head>

<body>

<p><a href="b.htm#10">1</a></p>
<p><a href="b.htm#20">2</a></p>
<p><a target="I2" href="b.htm#30">3</a></p>
<p>4</p>
<p>5</p>
<p>6</p>
<p>7</p>
<p>8</p>
<p>9</p>
<p><a name="10">10</a></p>
<p>11</p>
<p>12</p>
<p>13</p>
<p>14</p>
<p>15</p>
<p>16</p>
<p>17</p>
<p>18</p>
<p>19</p>
<p><a name="20">20</a></p>
<p>21</p>
<p>22</p>
<p>23</p>
<p>24</p>
<p>25</p>
<p>26</p>
<p>27</p>
<p>28</p>
<p>29</p>
<p><a name="30">30</a></p>
<p>31</p>
<p>32</p>
<p>33</p>
<p>34</p>
<p>35</p>
<p>36</p>
<p>37</p>
<p>38</p>
<p>39</p>
<p>40</p>
<p> </p>

</body>

</html>
******************
c.htm
<html>

<head>
<title>gggggggggg</title>
</head>

<body>
a<br>
b<br>
c<br>
e<p>
<iframe name="I2" src="b.htm">do not support</iframe>
</p>
<p><a href="a.htm">back</a></p>

</body>

</html>

ShawnR

2:25 pm on May 31, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi liwei, and welcome to WebmasterWorld!

I can't suggest an elegant method to fix it (hopefully someone else with more knowledge can). I can suggest 2 alternative fixes, neither of which are elegant:

Method 1:
=========
Use frames instead of an iframe. i.e put your iframe in a frame, and put the rest of your web page which surrounds it in a number of frames (you may need up to 4: one for what is above your iframe, one for what is below it an done for what is on either side.)

Method 2:
=========
In a.htm, define ><a name="top"> at the top of the body. Use javascript with the onclick method to first do the equivalent of <a target="I2" href="b.htm#30"> then do the equivalent of <a target="_parent" href="a.htm#top"> then return false; In the normal href= part of the <a...> tag just keep it the way it is, that way people with Javascript turned off can still use your site, albeit with the scrolling effect you don't want.

Shawn

PS. I see you posted the same question to the ASP/microsoft forum as well. Probably best to avoid doing that.

liwei

1:38 pm on Jun 1, 2003 (gmt 0)

10+ Year Member



Thank you,ShawnR

I cannot use method #1,as then menu in the top frame cannot go out of the frame.

Mothod #2 may work, I tried it, but I could not write correct code.

Can you give me an example code?

ShawnR

2:29 pm on Jun 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What I had in mind was something like:

<a href="b.htm#10" onclick='document.location.href="b.htm#10"; parent.location.href="a.htm#top"; return false;'>click here</a>

(All on one line)

However, doing the ...location.href="a.htm#top" will reload your original web page, so it may reload the iframe. So it may not work; give it a try.

I don't really understand why you can't do method one (although I agree it is not elegant).

Shawn

gph

3:07 pm on Jun 1, 2003 (gmt 0)

10+ Year Member



Hi guys

Just an idea and I don't have time to test it but you might be able to store the document.body.scrollTop and document.body.scrollLeft before following the link then ScrollTo(old_scrollLeft, old_scrollTop)

liwei

1:32 am on Jun 2, 2003 (gmt 0)

10+ Year Member



It's a good idea.
I have a function "scrollup" in the parent page.
I call the function from iframe, It scrolls back.

There is still one question:
How do I call the function?
What's a proper event?
Now, I am using onmouseover event. I don't think it is a good method.

The best time to call the function is after the iframe page has been loaded.

ShawnR

1:52 am on Jun 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The onload() event fires after the page has loaded, so put it in the onload attrribute of the body tag of the iframe. i.e. in your example, in b.htm's <body ...> tag.

liwei

1:59 am on Jun 2, 2003 (gmt 0)

10+ Year Member



I tried to use onload() event, it did not work. Maybe the onload() event fires before page loaded, not after.

ShawnR

2:29 am on Jun 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



onload fires after the page has loaded, but I suppose that since it is an internal link, the page does not reload.

You can use the onscroll event... It is not part of the standard events for the body tag, but it is supported by IE 4 onwards.

For a more cross-browser solution, one option is to use the onclick event of the <a...> tag to set a timer, then reposition the parent after the timeout has expired.

Shawn

gph

2:24 am on Jun 5, 2003 (gmt 0)

10+ Year Member



Did you get something to work?

The best I got was a quick jump in IE. It's fast but it's annoying.

I may be able to cover the page with the background colour while it jumps but I don't think that's much better.

liwei

4:03 pm on Jun 7, 2003 (gmt 0)

10+ Year Member



no, I don't have a good method to do it.
I wish if the quick jump or scrolling function could been run one only time after the clicking in iframe, otherwise, it scrolls up all the time. I even could not reach the bottom of the page. It is really annoying.