javascript - How Can I execute a PHP function inside a Script tag? -


so have function css looks this

function include_css($css="") { include(site_root.ds.'includes'.ds.'stylesheets'.ds.$css); } 

and in header use call it

<style type="text/css"><?php include_css('public.css'); ?></style> 

i similar function call javascript file load in ckeditor

function include_javascript($js="") { include(site_root.ds.'includes'.ds.'ckeditor'.ds.$js); } 

but bit of code doesn't work

<script type="text/javascript"><?php include_javascript('ckeditor.js'); ?></script> 

the tool bar doesn't show when doing way. show when use website.

<script src="//cdn.ckeditor.com/4.5.11/standard/ckeditor.js"></script> 

why doesn't work same way style tag? since doesn't work there similar way put php script tag?

i put php code inside of script tags instance set initial value of javascript variable. there no particular issue inserting php tags inside of script tag.

normally load javascript separately speed page load this:

<script src="/path-to_js/js-file.js" type="text/javascript"></script> 

so should work:

function include_javascript($js="") {     if ($js)         echo "<script src=\"/js-path/$js\" type=\"text/javascript\"></script>"; } 

if trying embed javascript code html doing ought work. noticed setting default value parameter. make sure passed , file exists. if result

<script></script>  

then 1 of these problem.


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -