Welcome to WebmasterWorld Guest from 54.167.85.221

Forum Moderators: open

Message Too Old, No Replies

How To Strip Out Named Anchors From URL's?

Use Javascript to Get Rid of # in the url

     

jimh009

9:17 am on Jun 5, 2013 (gmt 0)

10+ Year Member



Hi,

I recently re-designed a web page. As part of the re-design, I used eight named anchors to allow people to quickly jump to specific categories on the page.

The problem is that when someone clicks on a category link, in the URL bar the link changes from www.mysite.com/mypage.htm to www.mysite.com/mypage.htm#category1

Normally, this isn't a huge deal. However, on one particular long-established page this is causing a few issues since people click a category, scroll around and then click a link on my page that leads off-site, then hit their browsers back button to return to my page. The problem is that when people come back to my page, they often aren't going back to precisely where they were due to the named anchor in the url.

My thought was to use javascript to strip out the named anchor from showing at all in the URL bar. Thus, when someone clicks on a named anchor on the page, the url shown in the browser doesn't change.

Any ideas on how someone who knows less about javascript than the back side of the moon can do this?

Thanks

Jim

Fotiman

12:56 pm on Jun 5, 2013 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



That is standard browser behavior. Every site out there that uses named links will behave that way, so trying to customize your own site to behave differently is not a good idea.
Also, what you're asking is not really possible.

lucy24

8:41 pm on Jun 5, 2013 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



My thought was to use javascript to strip out the named anchor from showing at all in the URL bar. Thus, when someone clicks on a named anchor on the page, the url shown in the browser doesn't change.

Then how would the browser know that they're supposed to be somewhere other than the top of the page?

JD_Toims

6:08 pm on Jul 20, 2013 (gmt 0)

WebmasterWorld Senior Member Top Contributors Of The Month



I'd look into onUnload onClose & replaceState/pushState

Here's the official replaceState/pushState info:
http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#dom-history-replacestate

The rest is fairly simple to find plenty of info on all over the place.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month