...

View Full Version : go to specified position in another page



krishna
11-11-2004, 06:20 AM
help,
i want move to a pericular possition in another page,
ex:if i click on xxxxx in one page , iwant to go exactly where apporiate content is present in another page.

Kor
11-11-2004, 09:40 AM
Pass a parameter through Address bar
Example:
index is


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script language="JavaScript" type="text/JavaScript">
function goA(s){
if(s.selectedIndex>0){
var a=s.options[s.selectedIndex].text;
location.href='next.html'+'?'+a;
}
}
</script>
</head>
<body>
choose the desired anchor where to scroll next.html page<br>
<select onchange="goA(this)">
<option>--choose an anchor--</option>
<option>one</option>
<option>two</option>
<option>three</option>
</select>
</body>
</html>


next.html is


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script language="JavaScript" type="text/JavaScript">
function scrollA(){
var anc = location.href.split('?')[location.href.split('?').length-1];
var loc = location.href.split('?')[0];
location.href=loc+'#'+anc
}
onload = scrollA;
</script>
</head>
<body>
NEXT PAGE<br>
<a name="one"></a>
anchor one<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<a name="two"></a>
anchor two<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<a name="three"></a>
anchor three<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</body>
</html>


You may do similar if you want to go to a specific position in pixels, using scrollTo() method. This case the parameter passed will be that position (take care that the parameter passed becomes a string, so it must be parsed afterwards)

Garadon
11-11-2004, 11:53 AM
he could also just write the # in your 1st peice of code instead of ? and then save the seond piece of code.

jbot
11-11-2004, 12:02 PM
er ... named anchors, anyone?

Garadon
11-11-2004, 02:39 PM
I thought what I suggested was named anchors if it ain't could u tell me what it a named anchor is?

Kor
11-12-2004, 07:33 AM
Garadon is absolutely right... I am used to pass the parameter with the "neutral" '?' most of the time, thus I didn't realize that in this perticula case it was enough to write directly the anchor name.



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script language="JavaScript" type="text/JavaScript">
function goA(s){
if(s.selectedIndex>0){
var a=s.options[s.selectedIndex].text;
location.href='next.html'+'#'+a;
}
}
</script>
</head>
<body>
choose the desired anchor where to scroll next.html page<br>
<select onchange="goA(this)">
<option>--choose an anchor--</option>
<option>one</option>
<option>two</option>
<option>three</option>
</select>
</body>
</html>


And now any code in next.html is unecessary.

krishna
11-13-2004, 04:38 AM
thank you friends.but my problem is if i have some 10 lines of text (example) in first page i.e 10 different lines ,if i click on first line it should go to first para of another page ,if i click on 6th line it should goto 6th para of another page.
once again thank you for your help.

Mr J
11-13-2004, 05:21 PM
<a href="page1.htm#para1">Link to page 1 and paragraph 1</a>
<a href="page2.htm#para6">Link to page 2 and paragraph 6</a>


<a name="para1"></a> Placed at the beginning of paragraph 1 in page1
Blah Blah Blah




<a name="para6"></a>Placed at the beginning of paragraph 6 in page2
Blah Blah Blah

krishna
11-15-2004, 04:37 AM
thank you very much , it is working. once again thak you.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum