0

what should I set in the header() php function as the content type of the web page, if it is a php file, and has html, php, css and javascript ?

header('Content-type: text/html; charset=utf-8');

because that script above doesn't work, when I view the source code of the i-frame..the javascript are not being included, why is this happening?

sasori
  • 5,249
  • 16
  • 86
  • 138
  • Why do you need to specify that ? – Shankar Narayana Damodaran Sep 24 '13 at 06:14
  • 1
    Your question has nothing to do with the encoding of the page. Please share more code, especially where you add your Javascript, and change the title of this question to something like "my Javascript is not being included" – mavrosxristoforos Sep 24 '13 at 06:15
  • basically it's a pop up box, using the fancybox, so ...the fancybox contains a mixture of html,javascript,css and php....there's no body tag, since I am using a php framework and I just rendered the view file partially inside that fancy box..the problem is, the javascript is not being recognized when i view the source code of the pop-up, when I added the header content type – sasori Sep 24 '13 at 06:19
  • is header(...) the first thing your php scripts is outputting ? check for any echo-s. – d.raev Sep 24 '13 at 06:51

2 Answers2

2

You (presumably) aren't delivering PHP to the client, but are running it on the server to generate some output. Since it isn't being send to the client, you shouldn't tell the client anything about it.

The remaining content can't be simply "HTML + CSS + JS". You probably have HTML with embedded CSS and JS. This is an HTML document. The types of the embedded content are described by the HTML.

Use a text/html content type (which you don't have to specify because PHP defaults to outputting one if you don't say otherwise).


there's no body tag

So you are outputting a fragment of HTML and not a complete HTML document? As far as I know, there is no standard MIME type for that.


the problem is, the javascript is not being recognized

This almost certainly has more to do with how you are manipulating the original document (presumably using innerHTML (assigning content that includes JavaScript to innerHTML results in the JS being ignored)) then with the way you are delivering the data to the browser.

Community
  • 1
  • 1
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0
text/html

your code will be processed at run time and output as html.

Arvind Sridharan
  • 3,885
  • 4
  • 29
  • 54
  • what should i do to fix it ?, for it to recognize the javascript,css and php ? – sasori Sep 24 '13 at 06:28
  • it will recognize the javascript and css. you don't need to do anything. In chrome, right click and hit inspect element. You should be able to see what the javascript and css issues are. – Arvind Sridharan Sep 24 '13 at 08:51