JavaScript Click to Print Function Help

This page USED to work and became persnickety. I'd love some help. If there's a problem here I don't see it.

<cfoutput>
<cfset theCount = 1>
   
   <div class="row">
     <div class="col-sm-12">
       <ol class="breadcrumb">
         <li><a href="#event.buildLink('main.index')#">Home</a></li>
         <li class="active">Events Calendar</li>
       </ol>
     </div>
   </div>

<div class="row">
       <div class="col-lg-3">
                    <div class="panel panel-default">
                       <div class="panel-heading">
                         <h3 class="panel-title">Calendars</h3>
                       </div>
                       <div class="panel-body">
                         <form name="calendar-Form" id="calendar-form" method="get" action="#event.buildLink('EventCalendar.ShowCalendar')#" class="form-horizontal" role="form">
                           <cfloop query="rc.EmployeesCalendars">
                                   <p><input type="checkbox" id="viewCalendar" name="viewCalendar" value="#rc.EmployeesCalendars.id#" <cfif isdefined("session.calendartoView")><cfif ListFind(session.calendartoview,rc.EmployeesCalendars.id,',')>checked</cfif></cfif>>&nbsp;<span style="background-color:###rc.EmployeesCalendars.calColor#">&nbsp;</span>&nbsp;#rc.EmployeesCalendars.category#</p>
                             </cfloop>
                                   <p> <input type="checkbox" id="regonly" name="regonly" value="1" <cfif isdefined("rc.regOnly")>checked</cfif>/><span>&nbsp;</span>&nbsp;Only registered for events</p>
                       <input type="submit" name="btnSubmit" id="btnSubmit" value="Search" class="btn btn-primary btn-block" />
                       </form>
                       </div>
                       </div>

                       <div class="panel panel-default">
                           <div class="panel-heading">
                             <h3 class="panel-title">Tools</h3>
                           </div>
                           <div class="panel-body">
                               <a class="btn btn-primary btn-block" onclick="ClickHereToPrint('#session.providername# Event Calendar Print Out');" href="javascript:;">Print Calendar</a>
                           </div>
                       </div>             
       </div><!-- col --->

       <div class="col-lg-9">
             <div id="divToPrint">
                 <div class="table-responsive">
                   <div id='calendar'></div>
               </div>
           </div>
       </div>
</div>

<iframe id='ifrmPrint' src='##' style="width:0px; height:0px;"></iframe>

<script type="text/javascript">
function ClickHereToPrint(val){
   try{ 
       var oIframe = document.getElementById('ifrmPrint');
       var oContent = document.getElementById('divToPrint').innerHTML;
       var oDoc = (oIframe.contentWindow || oIframe.contentDocument);
       if (oDoc.document) oDoc = oDoc.document;
       oDoc.write("<html><head><title>"+val+"</title>");
       oDoc.write("</head><body onload='this.focus(); this.print();'>");
       oDoc.write(oContent + "</body></html>");        
       oDoc.close();        
   }
   catch(e){
       self.print();
   }
}

$(document).ready(function() {
       var date = new Date();
       var d = date.getDate();
       var m = date.getMonth();
       var y = date.getFullYear();

       $('##calendar').fullCalendar({

           header: {
               left: 'title',
               //center: ''
               right: 'prev,next today'
           },                        

           events: [
               <cfif rc.getEvents.recordcount>
                   <cfoutput query="rc.getEvents">
                   {
                       color: <cfif len(calColor)>'###calColor#'<cfelse>'##6699CC'</cfif>,
                       title: '#event_name#',
                       start: new Date(#year(dateformat(rc.getEvents.date,"mm/dd/yyyy"))#, #month(dateformat(rc.getEvents.date,"mm/dd/yyyy"))-1#, #day(dateformat(rc.getEvents.date,"mm/dd/yyyy"))#, #hour(rc.getEvents.startTime)#, #minute(rc.getEvents.startTime)#),
                       url: '#event.buildLink("EventCalendar.CalendarDayView")#?DayToView=#dateformat(rc.getEvents.date,"mm/dd/yyyy")#',
                       allDay: false
                   }

                   <cfif theCount LT rc.getEvents.recordCount>,</cfif>
                   <cfset theCount = theCount+1>
                   </cfoutput>
               
               </cfif>
           ],    

           eventClick: function(event) {
               // opens events in a custom made fancybox window
               openiFrame(event.url);
               return false;
           }
       });
   });
</script>

<!-- page specific includes --->
<link rel='stylesheet' type='text/css' href='includes/fullcalendar-1.6.4/fullcalendar/fullcalendar.css' />
<script type='text/javascript' src='includes/fullcalendar-1.6.4/fullcalendar/fullcalendar.min.js'></script>
</cfoutput>

Open in new window

tryportAsked:
Who is Participating?
 
Michel PlungjanIT ExpertCommented:
Any console messages and does not not work in any browser?


Perhaps name the iframe and try

       var oIframe = document.ifrmPrintName.document;
       var oContent = document.getElementById('divToPrint').innerHTML;
       oIframe.write("<html><head><title>"+val+"</title>");
       oIframe.write("</head><body onload='this.focus(); this.print();'>");
       oIframe.write(oContent + "</body></html>");        
       oIframe.close();
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.