If you want to do something like this <? javascriptFunction() ?>, then no, because javascript is browser-side.
You can call javascript functions using php. Use "echo" One example... <? echo 'onclick="return javascriptfunction()..."'; ?> Code (markup): From this example you can see that you can do many things to call functions. If it's more complex than that, you can also include your javascript files within the php page just like you can with html pages. "echo" works.
Yes PCO that is what I meant, thanks too cool. I'll try it. Regarding the ... dots after the function, I only need the function, I don't really need that do I? Also, do I still need to call the external javascript file at the top of the page with the script tags? Or can I just have it inside the same directory or something?
No problem. You're correct, you don't need the dots. I put them there for illustration. Basically, you'll call the javascript file however you wish. If you do it in the php code (inside the <? ) then you'll need to write a line like: echo "<script language=...>"; But since you can go in and out of html coding on php pages, you could just put your javascript call to the external javascript file within your html pages as you normally would and when you bounce back into your php code on that page, as long as you use echo it will act the same as if you were only coding a html page. You main issue that may arise is getting the quotations correct. But it works. I go in and out of javascript all the time in my php files. If you find issues with it not working for you, post a little snippet of your code and we'll see if we can't get it working right.
Hmmm thanks a lot, still a bit confused. Just one reason of concern is I have one javascript that is mine that I would like to protect, but not my only reason for this original question. Regarding the external js protection though, any way to call on the external js with php, without revealing its external .js address? Appreciated! Jen
I'm sorry, I don't know if there is a way to protect a call to a javascript file. You might try using the php function include(). But you would still have to echo out the code to the browser as once said before, javascript is browser/client side processed. If you have a javascript that you're wanting to protect, I, myself am not sure of a way to do. Sorry.
Why not just rewrite the javascript as a php file and call it via ajax. That way nobody can steal your code.
Interesting thought but do you mean I have to rewrite all the javascript into php code instead? Thank ya!!
yes.. Ajax is in general speaking - "Javascript on steroids".. In ajax you can make server calls using Javascript+XML httprequest. Alternatively you can consider encrypting javascript to hide the code. (its not very effective though, but can save a lot of pain...)
You could also encrypt your Javascript code... http://www.google.com/search?q=java...ient=firefox-a&rls=org.mozilla:en-US:official Good luck!
hello. if you mean "calling a javascript using php file"? then yes, it is possible. just include the <script> tag (similar to calling css). hope this helps <SCRIPT language="JavaScript" SRC="http://www.yourdomain.com/jscript/xyz.js"></SCRIPT>