For simple links, all that HTML::anchor
does is it calls URL::site
and builds an a
tag with it.
You can just call that method yourself, like this:
...
window.location = "<?php echo URL::site($link . $test1->getid() . '/travel') ?>"
...
You will need to put this JavaScript in the page itself and not in an outside JavaScript file, but that's probably OK.
UPDATE: Here's a cleaner way to do it that I couldn't type in the mobile app last night...
The cleanest way to do this is probably to use data
-attributes:
HTML
<div class="general">
<div class"grip_box" data-url="<?php echo URL::site($link . $test1->getid() . '/travel') ?>">
<div class"count">
<?php echo HTML::anchor($link . $test1->getId() . '/travel#comments', count ($travelcomment)); ?>
<?php echo count($countnumber); ?>
</div>
<div class="title">
<?php echo HTML::anchor($link2 . $test1->getId() . '/view', $test1->getTitle()); ?>
</div>
</div>
<div>
JavaScript:
$(".grip_box").click(function() {
if ($(this).attr('data-url')) {
window.location = $(this).attr('data-url');
}
});
This is the most flexible because you can use it for any elements on the page with very little change to the code.
Alternatively, you could store just the id in a data
-attribute like this:
...
<div class"grip_box" data-itemid="<?php echo $test1->getid() ?>">
...
and then build the rest in the JavaScript:
...
window.location = "BEGINNING_OF_URL" + $(this).attr('data-itemid') + "/travel";
...