Click here to Skip to main content
15,896,727 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
XML
I have a hyperlink and I am trying to add spinner when you clink on the link.

Below is the code for the spinner, but it is not working for the hyperlink.
   
 <script type="text/javascript">
        function Spinner() {
           document.getElementById("spinning").style.display = "block";
            document.getElementById("testdiv").style.display = "none";
        }
    </script>
<div id="spinning" style="display: none;">
        <span>loading...</span>
    </div>
<div id="testdiv">

Hello, this is link for the test url
<asp:HyperLink ID="linkurl" runat="server" NavigateUrl="~/test.aspx"   OnClientClick="Spinner(); return true;">Testing</asp:HyperLink>
</div>

Can any one help me on this?
Thanks!
Posted
Updated 23-Sep-15 6:50am
v2
Comments
Andy Lanng 23-Sep-15 13:04pm    
I would suggest that you don't use the navigate irl. The page is prolly already posted so JavaScript won't run. Add window.location="/test.aspx" to the end of the spinner function
apr1234 23-Sep-15 14:09pm    
Then it is not showing me as URL(Hyperlink)
F-ES Sitecore 23-Sep-15 13:14pm    
If you're using IE then IE considers the page "dead" when you navigate away so it is ignoring your page updates. If you are using IE then try on Chrome or Firefox to see if that's what the issue is. I believe the solution to this quirk involves a timer. Either create a timer in your onclick for 100ms and when the timer fires do your show\hide code. If you google for something like "spinner not showing ie onclick" you might find solutions.

1 solution

I don't think you need a spinner here as you are navigating to another page. Spinner is mostly needed when there is a lot of processing which takes time and you want to show it to user.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900