Developer forum

Forum » Development » javascript with xslt menu

javascript with xslt menu


Reply

i have a write a javascript which does something like this

function showAccessibleVersion()

{
var

location=window.location.href.replace("&accessibility=true","").replace("&accessibility=false","");
location+=location.substr(window.location.href.length-5,5)=='.aspx'?'?accessibility=true':'&accessibility=true';
window.location.href = location;
}

 

and i am trying to put it in my menu xslt that i have for the site!!

the java script works fine! the problem is when i put in the xslt file like this

 

 <xsl:template match="/NavigationTree">
            <ul>
          <xsl:apply-templates select="Page">
          </xsl:apply-templates>
        </ul>
        <script type="text/javascript" src="/Files/Templates/Navigation/accessibility.js">void(0);</script>
             <script type="text/javascript">showAccessibleVersion();</script>
              </xsl:template>

 

when i try to navigate the site menu it i understand that it runs forever and doesn't stop!!

Always trying to change the window.location.href i want this javascript to run only once in every click!! any idea because i am new with xslt!!
 


 


Replies

 
Reply

Your <script type="text/javascript">showAccessibleVersion();</script> doesn't seem to be encapsulated in anything, so it will be rendered the way you write it, thus refreshing the page automatically.

 

How about something like this instead:

 

<ul onclick="showAccessibleVersion();" />

 
Reply

can you be a little more specific with these ??

 

what i have to do with the java script in the way that will stop and run only once!!

 

function showAccessibleVersion(){

var location=window.location.href.replace("&accessibility=true","").replace("?accessibility=true","").replace("&accessibility=false","").replace("?accessibility=false","");
    location+=location.substr(window.location.href.length-5,5)=='.aspx' ? '?accessibility=true':'&accessibility=true';
    window.location.href = location;
     return;
   }

 

 

thanks in advance

stavros

 
Reply
stavros.solo wrote:

can you be a little more specific with these ??

 

what i have to do with the java script in the way that will stop and run only once!!

 

function showAccessibleVersion(){

var location=window.location.href.replace("&accessibility=true","").replace("?accessibility=true","").replace("&accessibility=false","").replace("?accessibility=false","");
    location+=location.substr(window.location.href.length-5,5)=='.aspx' ? '?accessibility=true':'&accessibility=true';
    window.location.href = location;
     return;
   }

 

 

thanks in advance

stavros


 

When you just do this: <script type="text/javascript">showAccessibleVersion();</script>
 

 

It will never stop running. If will refresh each time it reaches this line. But if you run it based on an onclick event or a conditional, you're able to control it. I don't know, what you're trying to acheive, but you could post the complete code with a description, and I could have a look at it.

 
Reply
Sorensen wrote 

When you just do this:

<script type="text/javascript">showAccessibleVersion();</script>
 



thanks a lot it works fine now you really helped me out !!! :) 

 

 

 

 
Reply
stavros.solo wrote:
Sorensen wrote 

When you just do this:

<script type="text/javascript">showAccessibleVersion();</script>
 

 

It will never stop running. If will refresh each time it reaches this line. But if you run it based on an onclick event or a conditional, you're able to control it. I don't know, what you're trying to acheive, but you could post the complete code with a description, and I could have a look at it.

 

The xslt code that i use for the menu

 

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >

  <!--
  Description: ul/li based top navigation (left-to-right). All features from admin implemented.
  Recommended settings:
  Fold out: False (True is deprecated, and will slow performance due to excessive data)
  Upper menu: Dynamic or Static
  First level: > 0
  Last level: = First level (Should be unselected or the same as first level)
  -->
  <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"  encoding="utf-8" />
  <xsl:param name="html-content-type" />

  <xsl:template match="/NavigationTree">

            <ul>
          <xsl:apply-templates select="Page">
          </xsl:apply-templates>
        </ul>

        <script type="text/javascript" src="/Files/Templates/Navigation/accessibility.js">void(0);</script>
            <!--<script type="text/javascript">showAccessibleVersion();</script>-->
              </xsl:template>
  <xsl:template match="//Page">

  <li>
     <a>
        <xsl:if test="@Allowclick='True'">
            <xsl:attribute name="href">
            <xsl:value-of select="@FriendlyHref" disable-output-escaping="yes"/>
                 </xsl:attribute>
        </xsl:if>

       <xsl:attribute name="title">
      <xsl:value-of select="@MouseOver" disable-output-escaping="yes"/>

       </xsl:attribute>
        <xsl:value-of select="@MenuText" disable-output-escaping="yes"/>.
     </a>

    <xsl:if test="(@ChildCount>=2)  and (@Active='False' or @InPath='True')" > 
                   
          <ul>
          <xsl:apply-templates select="Page">
          </xsl:apply-templates>
         </ul>

        </xsl:if>
 

  </li>

  </xsl:template>
</xsl:stylesheet>

 

i want every time i navigate to the menu tree to replace the

window.location.href with  window.location.href+"&accessibility=true" that's the reasean i write the javascript in this way!!

 

function showAccessibleVersion(){
    var location=window.location.href.replace("&accessibility=true","").replace("?accessibility=true","").replace("&accessibility=false","").replace("?accessibility=false","");
    location+=location.substr(window.location.href.length-5,5)=='.aspx' ? '?accessibility=true':'&accessibility=true';
    window.location.href = location;
}
 

 


 

Ah, Ok. Try this:

function showAccessibleVersion(){

    if (document.location.href.indexOf("accessibility") == -1){
    var location=window.location.href.replace("&accessibility=true","").replace("?accessibility=true","").replace("&accessibility=false","").replace("?accessibility=false","");
    location+=location.substr(window.location.href.length-5,5)=='.aspx' ? '?accessibility=true':'&accessibility=true';
    window.location.href = location;
}

}

 

So you only refresh if accessibility is not already in the address string.

 
Reply

I'm glad to hear so:)

 

You must be logged in to post in the forum