Log in

View Full Version : how do i insert a javascript in the body of a web page made in php



asiatic
11-11-2011, 07:35 AM
how do i insert a javascript in the body (not head) of a web page made in php: http://www.stampsworldindia.com/essentials/early_cancellations/

earlier i had the same page done in html where i could insert the thumbnail script in the head of the document
Now the site is being done in php & i have been told i can only put the (http://www.dynamicdrive.com/dynamicindex4/thumbnail.htm) java script in the body of the webpage and not the head , so how can i do that?

please help!

traq
11-11-2011, 03:27 PM
Your question is unclear.
Please provide more information, and be as specific as possible.
What do you want to accomplish? What have you already tried? What problems did you encounter?
Also, please be sure that you have included all relevant code and/or a link to the page in question.

PHP writes javascript the same way it writes html.
<?php
$js = '<script>alert("Javascript!");</script>';
print $js;
?>Your question, however, is very vague.

Is this a script you are writing? You need to learn more about PHP.

Is this a script someone else wrote? Ask them how to integrate your javascript.

Is this a CMS (like Wordpress or Joomla)? You need to learn about how that CMS works (and probably more about PHP in general as well).

I'm sorry I can't offer anything more constructive, but you haven't really asked a question here - you've just stated that you don't know how to do something, without offering any context or clue as to your goals or specific problem.

If you're looking for someone to do this for you, you should post in the Paid Work (http://www.dynamicdrive.com/forums/forumdisplay.php?f=30) forum.

djr33
11-11-2011, 06:14 PM
As a very general response, it is possible to put Javascript (<script> tags) anywhere on your page that you'd like. Sometimes it's better to put them lower (in the body section) so that they load after the rest of the page loads. That can make the page appear to load faster. It's not require that anything goes in the head, but it DOES change the order of things. So sometimes you will need a script in the head section so that it sets up something correctly later on the page or you might experience a delay or a broken script because it wasn't set up in the correct order.

It's easy to test this: just add the content in the body section. (Near the topic is probably safest, but that's not an absolute rule.) And if that works, great. If not, you will need to find out how to edit the head section. Many CMS setups make this difficult, but if you're creating it yourself you can usually find a (complicated) way around it. If not, you may need to ask the creators, OR you might just need to change systems-- if it doesn't do everything you need, you might need a new system.

I don't know about this script in particular, whether it requires that the code is in the head section or not. But again, that's something you can test.