Re: innerHTML triple quotes issue

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Sep 15, 2011 at 5:01 AM, Grega Leskovšek <legrega@xxxxxxxxx> wrote:
>
> <h3>My Heavenly profession is being <span class="see"
> onmouseover='<?php echo "this.innerHTML=' <img
> src=\"http://imagecache2.allposters.com/images/PF_New/102008/3070943.jpg\";
> alt =\"close to my heavenly face\" />'";?>'
> onmouseout="this.innerHTML='an angel'">an angel</span>,
>
>
> I first tried this but got a mistake and then I tried to use php to
> settle this look above, but got parsing mistake.
>

It's easy to forget that, although you are embedding JavaScript in the
onmouseover and onmouseout attributes of the element, the content of
those attributes is still technically HTML, so the single and double
quotes as well as the tag angle brackets inside the attribute should
probably be the HTML entities (&quot; &apos; &lt; and &gt;) instead of
the literal characters. This avoids the issue with nesting and
escaping quotes across three languages (PHP -> HTML -> Javascript).


Of course, when testing this, my first attempt worked in Firefox,
Opera, Safari and Chrome but failed in IE (version 8). (Go figure)

<span class="see"
onmouseover="this.innerHTML=&apos;&lt;br&gt;&lt;img
src=&quot;http://imagecache2.allposters.com/images/PF_New/102008/3070943.jpg&quot;
/>&apos;"
onmouseout="this.innerHTML=&apos;an angel&apos;"
>
an angel</span>



So then I tried a mixed approach and it seems to work in all of them:

<span class="see"
onmouseover="this.innerHTML='&lt;br&gt;&lt;img
src=&quot;http://imagecache2.allposters.com/images/PF_New/102008/3070943.jpg&quot;
/>'"
onmouseout="this.innerHTML='an angel'"
>
an angel</span>


YMMV

Andrew

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux