Welcome Guest, Not a member yet? Register   Sign In
Hash in url using redirect function
#1

[eluser]Freeze Dried Pop[/eluser]
Is there a way to get a hash onto the end of a url using code igniters built in functions e.g.

I append html to the end of my url's.

If I wanted to redirect to:

mydomain.com/blog/article/3/article-title.html

I would just use:

redirect(blog/article/3/article-title);

And it would do the rest.

But say I wanted to redirect to:

mydomain.com/blog/article/3/article-title.html#comment_13

How would I go about that? I can't put the hash in the string being sent to the redirect function since it will be wind up being

mydomain.com/blog/article/3/article-title#comment_13.html

But as far as I can tell it's not catered for at all with any other functions....
#2

[eluser]R_Nelson[/eluser]
you could do
Code:
mydomain.com/blog/article/3/article-title/comment_13/

if im reading what you want that should work!
#3

[eluser]Freeze Dried Pop[/eluser]
Not really I want to go to the article page and the comments will all have ids like so:

<code>
<div class="comment" id="comment_12">
My comment!
</div>
<div class="comment" id="comment_13">
Another comment!
</div>
</code>

So when I go to:

mydomain.com/blog/article/3/article-title.html#comment_13

The page (in most browsers) will automatically scroll down to the div with id "comment_13" once its loaded.

Which is why it needs to be in a hash not as part of the url
#4

[eluser]R_Nelson[/eluser]
i did misread what ya meant then
#5

[eluser]Freeze Dried Pop[/eluser]
I don't know if it's a perfect solution but I discovered that there's a site_url function which the redirect function runs through so I just used that and appended the hash tag onto the end.

Code:
$url = site_url(blog/article/3/article-title);

redirect($url.'#comment_13');

I suppose that it should still work even if you change the suffix away from ".html", although don't quote me on that as I haven't investigated how all browsers perform.




Theme © iAndrew 2016 - Forum software by © MyBB