homepage Welcome to WebmasterWorld Guest from 54.161.155.142
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
How To Strip Out Named Anchors From URL's?
Use Javascript to Get Rid of # in the url
jimh009




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

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




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

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




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

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




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

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved