Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2005
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Can I put PHP code inside Javascript .js file?

    Hi,
    I have a javascript .js file, can I have php code like <?=$myvar;?> inside the .js file? will it work?
    many thanks.

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    If your server is set to parse .js as php, then yes.
    Otherwise, you can change the filename to .php and that will work too...

  • #3
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Either will work, as long as it's parsed. Example .htaccess:

    Code:
    <Files file.js>
    ForceType application/x-httpd-php
    </Files>
    "$question = ( to() ) ? be() : ~be();"


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •