none
How can I remove hyperlink from Calendar web bart events?

Answers

  •  

    Hi,

    The theory of the code is to find the elements in page by identification, then remove their “onclick” and “href” attributes with JQuery. Try the code below:

    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
    
    <script type="text/javascript">
    
        $(document).ready(function(){              
    
          $('.ms-cal-dayitem').each(function(){                         
    
                $(this).removeAttr('href'); 
    
                $(this).removeAttr('onclick');                         
    
                $(this).closest("td").removeAttr('href');            
    
                $(this).closest("td").removeAttr('onclick');
    
           });
    
        $('.ms-cal-defaultbgcolor').each(function(){     
    
                $(this).removeAttr('href'); 
    
                $(this).removeAttr('onclick');                         
    
                $(this).children("a").removeAttr('href');            
    
                $(this).children("a").removeAttr('onclick');
    
           });
    
        });
    
    </script>

    Thanks.


    Emir Liu

    TechNet Community Support

    • Marked as answer by emjem Monday, February 20, 2012 9:42 PM
    Monday, February 20, 2012 2:56 AM

All replies

  • Hi,

    Please follow the steps:

    1. Open Calendar in DAY view, edit this page and add a Content Editor Web Part to the bottom.
    2. Copy the code below into Source Editor of CEWP.

    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
    <script type="text/javascript">
           $(document).ready(function(){              
                              $('.ms-cal-dayitem').each(function(){                         
                              $(this).removeAttr('href'); 
                              $(this).removeAttr('onclick');                         
                              $(this).closest("td").removeAttr('href');                         
                              $(this).closest("td").removeAttr('onclick');
                   });
        });
    </script>

    Please inform us the result.

    Thanks.



    Emir Liu

    TechNet Community Support


    Monday, February 13, 2012 5:56 AM
  • Hi Emir,

    thanks for this. unfortunately it doesn't work for me. Nothing breaks, but the hyperlinks remain active and can be clicked to open the DispForm, which is what I am trying to stop on this particular web part.

    I do have a number of other scripts on this page to render colour-coded events and Easy Tabs (Christoph's tools) and another script to remove links from lookup columns. I have closed all of these and re-tried this script but still no good. Then I changed the calendar view to use the default Title field instead of the colour-coded calculated field. Still no good.

    I also uploaded the jquery to a library which all authenticated users have read access to, and modified the reference. Here's the changed script (it didn't work when the script still referred to the original jquery source either):

    <script type="text/javascript" src="http://sp.int.ncahs.net/sites/cs/SiteDirectory/OCIO/SharePoint%20Admin/jquery-latest.js"></script>
     <script type="text/javascript">
            $(document).ready(function(){             
                               $('.ms-cal-dayitem').each(function(){                        
                               $(this).removeAttr('href');
                               $(this).removeAttr('onclick');                        
                               $(this).closest("td").removeAttr('href');                        
                               $(this).closest("td").removeAttr('onclick');
                    });
         });
     </script>

    I appreciate the attempt. Any other ideas?

    Thanks again for the assistance.


    Mark


    • Edited by emjem Friday, February 17, 2012 5:36 AM type
    Friday, February 17, 2012 5:28 AM
  • Hi emjem,

    Please make sure you open the DAY view first, then add the Content Editor Web Part. The order is important.

    Thanks.


    Come on!

    Friday, February 17, 2012 6:33 AM
  • Hello again Emir,

    I did try it in that order. Added Calendar Web Part to page, changed view from default list view to a DAY view, added CEWP. To make sure I tried it again on a DAY view in the actual Calendar list. Still doesn't work for me I'm afraid.

    I have uploaded a screen shot which shows the script I have placed at the bottom of the page. When I exit edit mode the calendar view continues to have active hyperlinks.

    Any further suggestions would be welcome, I really want to disable the links so that staff can view this in a web part but cannot open the event in the DispForm.

    Thanks again.

    Screen Shot


    Mark

    Friday, February 17, 2012 11:54 PM
  • Hi,

    In the screen shot I noticed that another CEWP, so please change the two CEWPs’ position to make the Remove Hyperlinks CEWP nearer to calendar, because some customizations can make change of page’s structure.

    If it still doesn’t work, please create another calendar without any customization to see if the script works.

    Note: the script only works when show calendar in Day view and Week view.

    Thanks.


    Come on!

    Saturday, February 18, 2012 3:14 AM
  • G'day,

    I had already tried that. I created a fresh view using the Title (instead of the calculated Display column which is renderd as html by the other script you mention), and removed all other hidden CEWP's form the page. The Events still have active links to DispForm.aspx

    I did notice that the script we have been trying to get to work refers to ms-cal-dayitem but when I look at the source for one of my day view pages there is no such reference.

    Here's a grab of what I believe is the relevant area. Does it offer any clues?


    Mark

    Saturday, February 18, 2012 3:39 AM
  • Hi,

    That's very helpful.

    If the event starts and ends in one day, the identification is ms-cal-dayitem, but if the event crosses days, the identification will change to ms-cal-dayMultiDay. So just change ms-cal-dayitem to ms-cal-dayMultiDay in script.

    Thanks.


    Come on!


    • Edited by HellenZhuang Saturday, February 18, 2012 4:06 AM
    Saturday, February 18, 2012 4:05 AM
  • Hello again,

    there will be both multi-day events, single day events and some of the single day events are actually recurrences. Will I need to modify the script further to pick up both classes? I think I can have a stab at this myself if I am on the rigt track, but I can't test till Tuesday (about 46 hours from now) so would appreciate it if you want to give me a clue about how to update the script....

    but more importantly I would appreciate it if a moderator DOESN'T mark my thread as answered so I can come back and report and/or acknowledge the folks that have helped me.... ;)

    I will check back before I try to adjust the script myself and afer to, hopefully, report the good news.


    Mark

    Saturday, February 18, 2012 11:50 PM
  •  

    Hi,

    The theory of the code is to find the elements in page by identification, then remove their “onclick” and “href” attributes with JQuery. Try the code below:

    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
    
    <script type="text/javascript">
    
        $(document).ready(function(){              
    
          $('.ms-cal-dayitem').each(function(){                         
    
                $(this).removeAttr('href'); 
    
                $(this).removeAttr('onclick');                         
    
                $(this).closest("td").removeAttr('href');            
    
                $(this).closest("td").removeAttr('onclick');
    
           });
    
        $('.ms-cal-defaultbgcolor').each(function(){     
    
                $(this).removeAttr('href'); 
    
                $(this).removeAttr('onclick');                         
    
                $(this).children("a").removeAttr('href');            
    
                $(this).children("a").removeAttr('onclick');
    
           });
    
        });
    
    </script>

    Thanks.


    Emir Liu

    TechNet Community Support

    • Marked as answer by emjem Monday, February 20, 2012 9:42 PM
    Monday, February 20, 2012 2:56 AM
  • Thank you, thank you, thank you!

    This works like a charm.

    I appreciate your help.

    Cheers,


    Mark

    Monday, February 20, 2012 9:42 PM