Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Vincent DeCapite 64 posts 83 karma points
    Oct 19, 2010 @ 18:52
    Vincent DeCapite
    0

    Javascript to have new window for link

    Hi There,

     

    I have an XSLT with the following code in it:

    <xsl:variable name="mediaId" select="number($product/data[@alias='productAnimation1'])" />

     

        <xsl:if test="$mediaId &gt; 0">

     

            <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />

     

            <xsl:if test="count($mediaNode/data) &gt; 0 and string($mediaNode/data[@alias='umbracoFile']) != ''">

     

                <a href="{$mediaNode/data[@alias='umbracoFile']}"><xsl:value-of select="$mediaNode/@nodeName"/><a/>

     

            </xsl:if>

     

        </xsl:if>

     

    What I am trying to do is to make that so when the link taht is generated is clicked, a new javascript window pops up with a predefine size.. I tried using this code: (Changing the link with Javascript)

    <a href="{$mediaNode/data[@alias='umbracoFile']}" target="_blank" onclick="MM_openBrWindow('{$mediaNode/data[@alias='umbracoFile']}','test1234','toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=200,height=100')">test

    Then I added a head script tag that was this:

    <script type="text/javascript">
    function MM_openBrWindow(theURL,winName,features) { //v2.0
      window.open(theURL,winName,features);
    }
    </script>

    The result of this is that it opens up two windows one with the predefined size, and one that is full sized...

    Any thoughts??

    Thanks For your help

  • Rich Green 2246 posts 4008 karma points
    Oct 19, 2010 @ 18:59
    Rich Green
    0

    Try changing

    <a href="{$mediaNode/data[@alias='umbracoFile']}" target="_blank" onclick...

    to

    <a href="#" onclick...

     Rich

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Oct 19, 2010 @ 20:57
    Chriztian Steinmeier
    0

    Hi Vincent,

    The reason you get the second ("normal") window is because you're allowing the browser to perform the normal click behaviour on a link (go to the URL in the href attribute) after executing the onclick handler. You should return false from the handler to prevent this:

    <a href="{$mediaNode/data[@alias = 'umbracoFile']}"> target="_blank" onclick="MM_openBrWindow(this.href, 'test1234', 'ALL_THE_FEATURES_HERE'); return false;">test</a>

    (I've also used this.href so you only have to remember to update the URL in one place)

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft