Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> JavaScript
Author Message
neralex
Site Admin



Joined: Aug 22, 2007
Posts: 1772

PostPosted: Sun Sep 16, 2012 2:13 pm Reply with quote

Hey guys!

I work at the moment on a solution to print the content in a colorbox and have some issues with it. I have found some hints on stack overflow. That works but the solution is not valid, because it writes a div and a body tag on a wrong place.

the examples:
[ Only registered users can see links on this board! Get registered or login! ] [ Only registered users can see links on this board! Get registered or login! ]

I'm working with RN25, inline js, colorbox and admin functions. I will try to give a example.:

Code:
function printcontent() {

   echo 'Here is my output text for the colorbox generated with database variables.';
}

function edit() {
   global $admin_file;
   $inlineJS = '<script type="text/javascript">' . PHP_EOL
           . '$(document).ready(function(){' . PHP_EOL
           . '   $(".printcbox").colorbox({' . PHP_EOL
           . '      opacity:0.50,' . PHP_EOL
           . '      width:\'730px\',' . PHP_EOL
           . '      innerWidth:700,' . PHP_EOL
           . '      height:"95%",' . PHP_EOL
           . '      iframe:true,' . PHP_EOL
           . '      onComplete: function() {' . PHP_EOL
           . '         $(\'#cboxContent\').ready(function(){' . PHP_EOL
           . '            $(\'#cboxContent\').append(\'<div id="cboxPrint" style="float: left;">print</div>\');' . PHP_EOL
           . '            $(\'#cboxPrint\').click( function() {' . PHP_EOL
           . '               printprepare();' . PHP_EOL
           . '            });' . PHP_EOL
           . '         });' . PHP_EOL
           . '      },' . PHP_EOL
           . '    });' . PHP_EOL
           . '});' . PHP_EOL
           . 'function printprepare(){' . PHP_EOL
           . '   try{' . PHP_EOL
           . '      var print_frame = document.getElementById(\'ifrmPrint\');' . PHP_EOL
           . '      var print_head = $("#cboxContent iframe").contents().find("head").html();' . PHP_EOL
           . '      var print_body = $("#cboxContent iframe").contents().find("body").html();' . PHP_EOL
           . '      var print_doc = (print_frame.contentWindow || print_frame.contentDocument);' . PHP_EOL
           . '      if (print_doc.document) print_doc = print_doc.document;' . PHP_EOL
           . '      print_doc.write(print_head);' . PHP_EOL
           . '      print_doc.write(\'<body onload="this.focus(); this.print();">\');' . PHP_EOL
           . '      print_doc.write(print_body);' . PHP_EOL
           . '      print_doc.close();' . PHP_EOL
           . '   }' . PHP_EOL
           . '   catch(e){' . PHP_EOL
           . '      self.print();' . PHP_EOL
           . '   }' . PHP_EOL
           . '}' . PHP_EOL
           . '</script>' . PHP_EOL;
   addJSToBody($inlineJS,'inline');
   include_once 'header.php';
   OpenTable();
   echo '<a class="printcbox cboxElement" href="' . $admin_file . '.php?op=printcontent" target="_blank">open colorbox content</a>';
   echo '<iframe id="ifrmPrint" src="#" style="width:0pt; height:0pt; border: none;"></iframe>';
   CloseTable();
   include_once 'footer.php';
}


With the following two lines i get the validation errors:

Code:
$(\'#cboxContent\').append(\'<div id="cboxPrint" style="float: left;">print</div>\');

print_doc.write(\'<body onload="this.focus(); this.print();">\');'


I know in the hint of stack overflow is written to use the inline mode and not the iframe method of the colorbox but i need the function printcontent for other things, too. Maybe someone has a better idea to solve it.

Thanks in advance.
 
View user's profile Send private message
kguske
Site Admin



Joined: Jun 04, 2004
Posts: 6433

PostPosted: Fri Sep 21, 2012 11:03 am Reply with quote

I believe there is a way with cdata to eliminate validation errors in JS. It's been a while since I looked at that. Maybe spasticdonkey can confirm...

_________________
I search, therefore I exist...
nukeSEO - nukeFEED - nukePIE - nukeSPAM - nukeWYSIWYG
 
View user's profile Send private message
spasticdonkey
RavenNuke(tm) Development Team



Joined: Dec 02, 2006
Posts: 1693
Location: Texas, USA

PostPosted: Fri Sep 21, 2012 12:58 pm Reply with quote

Nesting your code in something like this should kill those types of validation errors. It keeps the browser from parsing it as html.

<script type="text/javascript">
//<![CDATA[

//]]>
</script>


But unless the script needs PHP variables inserted dynamically, I would save the JS as a file instead of using the inline method. That will remove the validation errors without use of CDATA.
 
View user's profile Send private message Visit poster's website
kguske







PostPosted: Fri Sep 21, 2012 2:54 pm Reply with quote

thanks, spasticdonkey!
 
neralex







PostPosted: Tue Sep 25, 2012 10:37 am Reply with quote

Thanks, it works! Smile
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> JavaScript

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©