![]() |
page anchors - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: page anchors (/showthread.php?tid=26608) |
page anchors - El Forum - 01-18-2010 [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> 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. page anchors - El Forum - 01-18-2010 [eluser]Sean Gates[/eluser] You need a little more than uri_string. Use the URL helper and use site_url(): Code: <a href="<?=site_url($this->uri->uri_string());?>#top">Back to Top</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] page anchors - El Forum - 01-18-2010 [eluser]Sean Gates[/eluser] Even better, use current_url(): Code: <a href="<?=current_url();?>#top">Back to Top</a> page anchors - El Forum - 01-18-2010 [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. |