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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

STOP! Page from Changing Position When Link is Clicked

Status
Not open for further replies.

Chinyere

Programmer
Mar 9, 2001
79
US
Hello,

I am working with a list of links on a web page. When someone clicks on a link and it opens in a page, the page position of the original is NOT retained; it shoots up back to the top of the page. this is the problem. How do I get it to retain its position so that if someone is clicking on the 16th link, for example, the page does not return him to the top of the page after he clicks?

here is the applicabe (I think) ASP code:

<a href=&quot;#&quot;
onClick=&quot;window.open('ShowSome_detail.asp?f_ID=<%=rsDC.Fields(&quot;gd_key&quot;)%>','','resizable=yes,menubar=yes,scrollbars=yes,height=300,width=400')&quot;><i>
<%= rsDc.Fields(&quot;gd_Title&quot;) %></i></a>  (Date: <%= rsDC.Fields(&quot;gd_Year&quot;) %>) 
<% If rsDC.Fields(&quot;gd_zip&quot;)=true Then %>

Is there something I should change here? Thanks.

Chinyere [afro2]
 
Try that.

<a href=&quot;#<%=rsDC.Fields(&quot;gd_key&quot;)%>&quot; name=&quot;<%=rsDC.Fields(&quot;gd_key&quot;)%>&quot;
onClick=&quot;window.open('ShowSome_detail.asp?f_ID=<%=rsDC.Fields(&quot;gd_key&quot;)%>','','resizable=yes,menubar=yes,scrollbars=yes,height=300,width=400')&quot;><i>
<%= rsDc.Fields(&quot;gd_Title&quot;) %></i></a> (Date: <%= rsDC.Fields(&quot;gd_Year&quot;) %>)
<% If rsDC.Fields(&quot;gd_zip&quot;)=true Then %>
foo
 
That should focus on the link you clicked - the page will still move, but to a relevent link (the one you clicked). foo
 
try this:
Code:
<a href=&quot;javascript://&quot; 
onClick=&quot;window.open('ShowSome_detail.asp?f_ID=<%=rsDC.Fields(&quot;gd_key&quot;)%>','','resizable=yes,menubar=yes,scrollbars=yes,height=300,width=400')&quot;><i>
<%= rsDc.Fields(&quot;gd_Title&quot;) %></i></a>  (Date: <%= rsDC.Fields(&quot;gd_Year&quot;) %>)  
<% If rsDC.Fields(&quot;gd_zip&quot;)=true Then %>
Tony
reddot.gif WIDTH=500 HEIGHT=2 VSPACE=3

 
Or you could just define some anchors and in the href reference them:
Code:
<a name=&quot;detail_<%=rsDC.Fields(&quot;gd_key&quot;)%>_section&quot;></a>
<a href=&quot;#detail_<%=rsDC.Fields(&quot;gd_key&quot;)%>_section&quot; 
onClick=&quot;window.open('ShowSome_detail.asp?f_ID=<%=rsDC.Fields(&quot;gd_key&quot;)%>','','resizable=yes,menubar=yes,scrollbars=yes,height=300,width=400')&quot;><i>
<%= rsDc.Fields(&quot;gd_Title&quot;) %></i></a>  (Date: <%= rsDC.Fields(&quot;gd_Year&quot;) %>)  
<% If rsDC.Fields(&quot;gd_zip&quot;)=true Then %>

The # directs you to the top section of the page(not a null address as some people believe), by declaring an a name= section and then calling it in the href you are telling the page to move to a specific location, rather than the generic/defaul top of the page location.

-tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
With enough resources, time, and coffee, anything is possible.
 
Ack, sorry :p Blame it on trying to read the monitor after a very long workday :)
Sorry about that, and thanks for bringing it to my attention,

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
With enough resources, time, and coffee, anything is possible.
 
i believe all you need to do is add &quot;return false;&quot; to the onclick event in the link, and the link will not jump your page around. this &quot;return false&quot; will prevent the &quot;href&quot; from firing, but your onclick event still will. adjust as follows:

p.s., this is pure HTML, the ASP stuff has been stripped out for brevity

Code:
<a href=&quot;#&quot; 
onClick=&quot;window.open(...blahblahmyparamsblah...); return false;&quot;>
my linktext
</a>

conversly, i've also heard recently that some older IE browsers (maybe version 5?) have problem doing the javascript that way (i.e., using the '#' as the href)... so a more universal solution is to move your javaScript from the onClick to the href itself. then your page especially won't be moving anywhere. consider:

Code:
<a href=&quot;javascript:window.open(...blahblahmyparamsblah...);&quot;>
my linktext
</a>

good luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top