Tuesday, September 1, 2009

Re: How to not escape Javascript in html helper link

Use SINGLE QUOTES when need quotes in tag attributes. It is the basics
of HTML.

<?php
echo $html->link(
$html->image('an_image.jpg'),
'/image/a_link.php?test',
array(
'class' => 'image',
'escape' => false,
'onClick' => "pageTracker._trackEvent('category',
'action', 'label');"
),
false,
false
);
?>

On Sep 2, 12:15 am, Kana <kana....@gmail.com> wrote:
> How to not escape Javascript in html helper link without having to use
> Javascript outside $html->link?
>
> I try to achieve:
> - the quotes in the onClick event, either single or double quotes
>
> <a href="/image/a_link.php?test" class="image"
> onClick="pageTracker._trackEvent("category", "action", "label");">
>         <img src="/img/an_image.jpg" />
> </a>
>
> But the result I get when viewing pagesource is:
> - note the escaped quotes
> - I tried single and double quotes
>
> <a href="/image/a_link.php?test" class="image"
> onClick="pageTracker._trackEvent(&quot;category&quot;,
> &quot;action&quot;, &quot;label&quot;);">
>         <img src="/img/an_image.jpg" />
> </a>
>
> I use the following code:
>
> <?php
> echo $html->link(
>         $html->image('an_image.jpg'),
>         '/image/a_link.php?test',
>         array('class' => 'image', 'escape' => false, 'onClick' =>
> 'pageTracker._trackEvent("category", "action", "label");'),
>         false,
>         false
> );
> ?>
>
> There must be a way to onClick Javascript working in link? I Googled
> but couldn't find any topic on this.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: