E.6 Executing JavaScript from HTML Links

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Appendix E.  HTML Support in Text Fields

In most JavaScript-capable web browsers, it is possible to execute JavaScript statements from an anchor tag using the javascript: protocol as the value of the HREF attribute. For example:

<A HREF="javascript:square(5);">find the square of 5</A>

In ActionScript, we can also execute JavaScript statements from an <A> tag, like this:

theField_txt.htmlText = "<A HREF='javascript:alert(5);'>display the number 5</A>";

However, to include string values in JavaScript statements, we must use the HTML entity &quot; for quotation marks, as in:

theField_txt.htmlText = "<A HREF=                         'javascript:alert(&quot;hello world&quot;);'>"                         + "display hello world</A>";


    ActionScript for Flash MX. The Definitive Guide
    ActionScript for Flash MX: The Definitive Guide, Second Edition
    ISBN: 059600396X
    EAN: 2147483647
    Year: 2002
    Pages: 780
    Authors: Colin Moock

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net