We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Get Full URL with Hashtag

Development and Programming

AdamSmith's avatar
AdamSmith
22 posts
about 14 years ago
AdamSmith's avatar AdamSmith

Is there anyway to get the full URL of the current page with hashtag included?

For example if I’m on: http://domain.com/work#web

it would return: http://domain.com/work#web

       
Dan Decker's avatar
Dan Decker
7,338 posts
about 14 years ago
Dan Decker's avatar Dan Decker

Hi Adam,

It looks like Current URL will do exactly what you are looking for.

Let me know what you think!

Cheers!

       
AdamSmith's avatar
AdamSmith
22 posts
about 14 years ago
AdamSmith's avatar AdamSmith

Thanks for your reply Dan,

I gave that plugin a try, but unfortunately it doesn’t pull the hashtag.

so http://domain.com/work#web only pulls http://domain.com/work

       
Dan Decker's avatar
Dan Decker
7,338 posts
about 14 years ago
Dan Decker's avatar Dan Decker

Ok,

I tested this with PHP enabled in the template:

echo $this->EE->input->server('REQUEST_URI');

Which gets the request URI from the server. It seems that the “#value” is not returned as part of the request. It is handled at the DOM level in the browser, so you are left with looking for a JavaScript solution.

Cheers,

       
454 Creative's avatar
454 Creative
23 posts
about 14 years ago
454 Creative's avatar 454 Creative

Dan, thanks for going the extra mile.

My research led me to the same conclusion as yours. The anchor is only used on the client side.

Javascript it is!

       
upressplay's avatar
upressplay
18 posts
about 14 years ago
upressplay's avatar upressplay

I’ve been dealing with this issue also. My goal is to create a single user session environment that can be linked to each page, with dynamic meta data, social sharing and Google SEO crawls. What I found is that hash tag urls don’t allow this, no server side detection of the hash tag url. Noted above.

What I found was a html5 technique, that so far, is doing exactly what i needed. Rather than reading the url with jquery address, change the url using pushState.

var section_state = new Object();
var new_url = "/"+_url.data.url;
var new_title = "Site Name - "+_url.data.title;
 
history.pushState(section_state,new_title,new_url);  
var page_pathname = window . location . pathname;    
 
section_url = page_pathname.split("/")[1];   
subsection_url  = page_pathname.split("/")[2];

Granted, this solution has issues with older browsers. But, I foresee this as the way to go moving forward.

Reference: https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history http://blog.new-bamboo.co.uk/2011/2/2/degradable-javascript-applications-using-html5-pushstate http://badassjs.com/post/840846392/location-hash-is-dead-long-live-html5-pushstate

       
Dan Decker's avatar
Dan Decker
7,338 posts
about 14 years ago
Dan Decker's avatar Dan Decker

454 Creative, all,

Since this has morphed into a rather nice discussion, I’ll move it into Development and Programming so new info can be added over time.

Thanks to you all for adding in your expertise.

Cheers,

       
upressplay's avatar
upressplay
18 posts
13 years ago
upressplay's avatar upressplay

The following link shows how to track pushState changes with Google Analytics.

http://code.google.com/apis/analytics/docs/gaJS/gaJSApiBasicConfiguration.html#gat.GA_Tracker._trackPageview

       
Kaizien's avatar
Kaizien
1 posts
2 years ago
Kaizien's avatar Kaizien

Dan, appreciate your efforts. My findings align with yours; the anchor is client-side. Looks like JavaScript is the way forward. Thanks for confirming!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.