.... That worked

  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 477

Post 3+ Months Ago

So I code both Javascript and PHP and there are many many times where I need them to play nice together to make my life just a little bit easier. So I use a php file for external Javascript files, which works fine but since I use dreamweaver all of the Javascript code turns to black text which sucks to look at.

Example
JAVASCRIPT Code: [ Select ]
<script type="text/javascript" src="js_include.php?no_cache=<?php echo uniqid(); ?>"></script>
 
  1. <script type="text/javascript" src="js_include.php?no_cache=<?php echo uniqid(); ?>"></script>
  2.  


I got curious today and tried something I was sure would work and should have no issues and I decided to try it and it worked. What I did was in the js_include.php file I added script tags around all of the code but commented them out so when it ran as a Javascript file it would comment out the script tags. It color codes both Javascript and PHP and runs both.

js_test.php
HTML Code: [ Select ]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Javascript Test</title>
 
<!-- Javascript -->
<script type="text/javascript" src="js_include.php?no_cache=<?php echo uniqid(); ?>"></script>
 
</head>
 
<body>
</body>
</html>
 
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Javascript Test</title>
  6.  
  7. <!-- Javascript -->
  8. <script type="text/javascript" src="js_include.php?no_cache=<?php echo uniqid(); ?>"></script>
  9.  
  10. </head>
  11.  
  12. <body>
  13. </body>
  14. </html>
  15.  



js_include.php
JAVASCRIPT Code: [ Select ]
// <script type="text/javascript">
 
alert('Javascript is Running. Also PHP is processing no_cache = <?php echo $_GET['no_cache']; ?>. As a nice touch it color codes both PHP and JavaScript.');
 
// </script>
 
  1. // <script type="text/javascript">
  2.  
  3. alert('Javascript is Running. Also PHP is processing no_cache = <?php echo $_GET['no_cache']; ?>. As a nice touch it color codes both PHP and JavaScript.');
  4.  
  5. // </script>
  6.  


It will make looking at my script a lot easier on my eyes.
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 477

Post 3+ Months Ago

Your really only need the opening tag to trick dreamweaver I added the ending for my code completion quirks

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 83 guests
  • 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 post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.