Wednesday, September 2, 2009

Re: How to not escape Javascript in html helper link

Hi there, thanks for your quick reply.

I already mentioned trying both SINGLE quotes and DOUBLE quotes. Both
result in escaped quotes, hence this post.

The example you gave results in:

<a href="/image/a_link.php?test" class="image"
onClick="pageTracker._trackEvent(&#039;category&#039;,
&#039;action&#039;, &#039;label&#039;);"><img src="/img/an_image.jpg" /
></a>

Is there something I am overlooking here? Is it just not possible to
have Javascript in $html->link() ?

:)

Kana


On Sep 2, 4:03 am, "Dr. Loboto" <drlob...@gmail.com> wrote:
> Use SINGLE QUOTES when need quotes in tag attributes. It is the basics
> ofHTML.
>
> <?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 tonotescapeJavascriptinhtmlhelperlinkwithout having to use
> >Javascriptoutside $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 onClickJavascriptworking inlink? 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: