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 10 of 10
  1. #1
    New to the CF scene
    Join Date
    Sep 2003
    Location
    North Yorkshire, England
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question JavaScript include using .php file (not .js)

    Hello. I am currently experimenting with using PHP to generate a JavaScript array within a source file:

    <script language=JavaScript src=includes/preload.php></script>

    This works in all the browsers I've tested and treats the .php file like a .js file. Does anyone know of any browsers that can't do this?

  • #2
    New to the CF scene
    Join Date
    Sep 2003
    Location
    North Yorkshire, England
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oops - posted this in the wrong section. Sorry.

  • #3
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    As long as you send the correct MIME-type
    PHP Code:
    header"Content-type: text/javascript" ); 
    You'll be okay.
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Actually, the 'text/javascript' content type is wrong. The right one is 'application/x-javascript', and all JavaScript enabled browsers accept it in the Content-Type header, even though some doesn't accept it in the type attribute of the script element.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #5
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Very true - I too often forget that. Thanks for the correction, liorean
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #6
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72° W. 48' 57" , 41° N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    when did the mime-type change, and why? anyone got a link that explains?
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

  • #7
    New to the CF scene
    Join Date
    Sep 2003
    Location
    North Yorkshire, England
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Cheers guys. This works great.

  • #8
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Joh6nn - it never changed. 'text/javascript' never got registred (haven't even been suggested for registration at the IETF) and the 'application/x-<insert language, program or document format here>' is the default content type for new formats. Thus, 'application/x-javascript' is and always was the right content type for JavaScript, something as I mentioned all browsers accept in the Content Type header but not in the type attribute for some strange reason.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #9
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Oh, good thing you clarified in this nearly 5 year old thread.

  • #10
    Regular Coder
    Join Date
    May 2008
    Posts
    187
    Thanks
    7
    Thanked 7 Times in 7 Posts
    lol, and on his first post too!


  •  

    Posting Permissions

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