Welcome Guest, Not a member yet? Register   Sign In
page anchors
#1

[eluser]darkhouse[/eluser]
I've searched the forums, but can't find too much... I've got a simple CMS in the works, and I'm trying to use a Back To Top link throughout my content
Code:
<a href="#top">Back To Top</a>

When it's clicked, it doesn't just put #top at the end of the current url like domain.com/controller/method#top instead it loads the homepage. This is because of the base tag which is necessary to load everything properly... if the href includes the current uri like
Code:
<a href="URI_STRING#top">Back To Top</a>
//had trouble getting the $this->uri->uri_string() function to show up in the link here,
//but you get the idea...
it works fine... but again, I'm creating this content through a CMS, and ultimately it will be the client managing this content.

I have 2 possible solutions to this problem. I can either use jQuery or preg_replace to prepend any links that have a # with the current uri string. Does anybody else have any ideas?

Thanks.

Edit: I decided to do the preg_replace method, and it works fine, but if anyone has any other ideas, or even ideas why the preg_replace method might not work, please let me know. Thanks.
#2

[eluser]Sean Gates[/eluser]
You need a little more than uri_string. Use the URL helper and use site_url():

Code:
&lt;a href="&lt;?=site_url($this->uri->uri_string());?&gt;#top">Back to Top&lt;/a>

More info here: [url="http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html"]http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html[/url]
#3

[eluser]Sean Gates[/eluser]
Even better, use current_url():

Code:
&lt;a href="&lt;?=current_url();?&gt;#top">Back to Top&lt;/a>
#4

[eluser]darkhouse[/eluser]
Thanks, I was asking more about if there was a way to make those links relative to the current uri, other than what I came up with. The more I think about it, the more I'm sure there isn't, so the solution I did is the best one, I think.




Theme © iAndrew 2016 - Forum software by © MyBB