Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > anchors and window.history

Reply
Thread Tools

anchors and window.history

 
 
Timo
Guest
Posts: n/a
 
      12-10-2004
Is there any way to jump to an anchor in the current document without
affecting window.history?
Thanks


 
Reply With Quote
 
 
 
 
Ivo
Guest
Posts: n/a
 
      12-10-2004
"Timo" asks
> Is there any way to jump to an anchor in the current document without
> affecting window.history?


With the IE only method of scrollIntoView(), this is rather easy:

<a href="#jump"
onclick="if(document.getElementById(this.hash.repl ace(/^#/,''))){
document.getElementById(this.hash.replace(/^#/,'')).scrollIntoView(); return
false; }"
>From here</a>


....

<a id="jump">To here.</a>
--
Ivo
http://4umi.com/web/links.htm


 
Reply With Quote
 
 
 
 
McKirahan
Guest
Posts: n/a
 
      12-10-2004
"Ivo" <> wrote in message
news:41b9f0a2$0$80128$...
> "Timo" asks
> > Is there any way to jump to an anchor in the current document without
> > affecting window.history?

>
> With the IE only method of scrollIntoView(), this is rather easy:
>
> <a href="#jump"
> onclick="if(document.getElementById(this.hash.repl ace(/^#/,''))){
> document.getElementById(this.hash.replace(/^#/,'')).scrollIntoView();

return
> false; }"
> >From here</a>

>
> ...
>
> <a id="jump">To here.</a>
> --
> Ivo
> http://4umi.com/web/links.htm



This shorter form seems to work too:

<a href="#jump"
onclick="document.getElementById(this.hash.replace (/^#/,'')).scrollIntoView(
)">From here</a>

Any reason not to use it?


 
Reply With Quote
 
Ivo
Guest
Posts: n/a
 
      12-10-2004
"McKirahan" wrote
> "Ivo" wrote
> > With the IE only method of scrollIntoView(), this is rather easy:
> >
> > <a href="#jump"
> > onclick="if(document.getElementById(this.hash.repl ace(/^#/,''))){
> > document.getElementById(this.hash.replace(/^#/,'')).scrollIntoView();
> > return false; }"
> > >From here</a>

> > <a id="jump">To here.</a>

>
>
> This shorter form seems to work too:

<snip>

You just removed the if(...){ } test, as though it was there for no reason.
But there are some things in life that are just not reliable and this is one
of them. If the referred element does not exist for some reason (the page
did fully load for example, it happens on the best machines) an ugly error
may occur if you do not test for its existence before referring to it. This
is one of the most basic programming principles.
One should also test for the existence of the scrollIntoView() method before
using it (I copied the code from a local application, and forgot about
that). BTW, scrollIntoView() is a nice IE feature, but of course focus()
works on most other browsers too.
--
Ivo













 
Reply With Quote
 
Timo
Guest
Posts: n/a
 
      12-13-2004
Thanks for the suggestions!
Timo


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
iframes and anchors David Moore HTML 0 03-04-2006 10:07 PM
redirect, parameters and anchors JohnZing ASP .Net 3 08-23-2004 12:21 PM
What about Anchors (#) and ASP.NET? Lars Netzel ASP .Net 5 07-27-2004 12:57 PM
Use of acronym and abbr tags with anchors Rowan Malin HTML 10 05-14-2004 07:00 PM
Bookmark Anchors and VB.NET Chris M ASP .Net 1 10-24-2003 12:31 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57