javascript created links

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John

    javascript created links

    Hi, I want to set a directory and an image name as a js variable and
    later call those vars as and html link. I am not doing this correctly,
    so I ask for help. Any advice is appreciated. Chuck
    Here is a basic example.

    <script type="text/javascript" language="javas cript">
    var dirpath = " http://www.blah.com/images/",
    image1 = "de-01.jpg";
    </script>


    <a href="<script language="javas cript">document .write(dirpath +
    image1);</script>">image1 </a>
  • Michael Winter

    #2
    Re: javascript created links

    On Mon, 30 Aug 2004 00:35:29 -0500, John <john@mac.com > wrote:
    [color=blue]
    > Hi, I want to set a directory and an image name as a js variable and
    > later call those vars as and html link. I am not doing this correctly,
    > so I ask for help. Any advice is appreciated. Chuck
    > Here is a basic example.
    >
    > <script type="text/javascript" language="javas cript">[/color]

    The type attribute makes language redundant. That, and the fact that
    language is deprecated, means that you shouldn't use the language
    attribute.
    [color=blue]
    > var dirpath = " http://www.blah.com/images/",
    > image1 = "de-01.jpg";
    > </script>
    >
    > <a href="<script language="javas cript">document .write(dirpath +
    > image1);</script>">image1 </a>[/color]

    You'll have to write out the entire link:

    <script type="text/javascript">
    document.write( '<a href="' + dirpath + image1 + '">image1<\/a');
    </script>

    Note that the </a sequence is escaped. This should be done with all
    closing tags to ensure that the browser doesn't interpret </ as the end of
    the SCRIPT element.

    Hope that helps,
    Mike

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail.

    Comment

    Working...