ytsejam
ytsejam

Reputation: 3439

url hash fix needed

I am trying to use an ajax code in my site. My problem is that I want only to use last part of the link.. otherwise the hash value becomes as here :

http://localhos./~ytsejam/wlog/public/#http://localhos./~ytsejam/wlog/public/index.php/

This is my line and ajax code for hashing :

window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-4);  

and here is my menu item in the source

<li><a href="http://localhos./~ytsejam/wlog/public/index.php/abouts">HAKKIMIZDA</a></li>

.

How can I change subsrt value to work here?

Upvotes: 1

Views: 265

Answers (1)

Phil
Phil

Reputation: 165059

Rather than parsing URL strings, I suggest you be more explicit in assigning data.

Try something like this

<a href="http://localhos./~ytsejam/wlog/public/index.php/abouts"
   data-hash="abouts">HAKKIMIZDA</a>

Then use the data attribute in your event handler

window.location.hash = $(this).data('hash');

Update

Using HTML::link_to_route(), you would do something like

{{HTML::link_to_route('abouts', 'HAKKIMIZDA', array(), array(
    'data-hash' => 'abouts'
))}}

I suggest you become familiar with the documentation for your framework of choice.

Upvotes: 1

Related Questions