0

How can i insert this javascript code to a php block? I want to run this javascript in a php block.

<script src="http://www.example.com/index.php?section=serve&id=1&output=js</script>

1 Answer 1

0

It should be like this:

<script src="http://www.example.com/index.php?section=serve&id=1&output=js" language="javascript" type="text/javascript"></script>

It doesn't matter you are working in php or anything else. The fact is whenever the browser sees this tag, it will load the script file from the "src" url and executes everything inside the file. So put this tag whenever you wanna load the script in your html document.

Hope it helps Cheers

Sign up to request clarification or add additional context in comments.

5 Comments

certain browsers might also need you to set the appropriate Content-type header.. hence when serving JavaScript via a PHP script it might help to add a header("Content-type: application/javascript") before sending the actual data body.. stackoverflow.com/questions/3987384/…
Thank you @lostsource. Some facts will never change.
As i said, i want to place it on a block in Drupal 7. I did what you said but it doesn't work. I placed it as plain text, html, php but none of them didn't work. Whats your solution for it please?
May I ask you first explain what is the response of the "src" attribute, I mean the javascript code you want to be run, then I can say how to do the stuff.
Happy to hear that body,,, :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.