Jump to content

[resolved]javascript In Php


REY619
 Share

Recommended Posts

Hello, when i try to add the following javascript snippet in my php pages it doesnt output the result as it is supposed to, whereas the same code works fine in a html page.Here is teh javascript -

<script type="text/javascript" src="http://shoutcast.mixstream.net/js/song/uk3-free:24304">You appear to have javascript turned off.</script>

This is the syntax how i add it in my php pages -

<?phpecho "<script language=\"Javascript\" src=\"http://shoutcast.mixstream.net/js/status/uk3-free:24304\">";echo "You appear to have javascript turned off.";echo "</script>";

?>It just outputs a blank page.Please tell me what i am doing wrong.Thanks.

Edited by REY619
Link to comment
Share on other sites

Try to switch to single quotes, at least for this one:

echo '<script type="text/javascript" src="http://shoutcast.mixstream.net/js/song/uk3-free:24304">';echo 'You appear to have javascript turned off.';echo '</script>';

If that doesn't work, make sure the code is being outputted properly. Do a "View Source" on the page to see if it is printed out.On an unrelated (sort of) note:1. ditch the "language" attribute. Use the "type" one instead.2. The contents of the script element isn't going to be shown if the user has disabled JavaScript. It will be shown if the browser doesn't support JavaScript (i.e. in Netscape 2 or something...). Simply put - it's basically useless.

Link to comment
Share on other sites

Tried the single quotes.. No help. Still blank page.Viewing the source shows the correct code i.e. -

<script type="text/javascript" src="http://shoutcast.mixstream.net/js/song/uk3-free:24304">You appear to have javascript turned off.</script>

Edited by REY619
Link to comment
Share on other sites

Is it this message that isn't working for you: You appear to have javascript turned off.The space between script tags is supposed to be empty when the script has a src attribute. Text between the tags is not supposed to print if JavaScript is disabled. It's a neat concept, and maybe it used to happen like that, but it is not part of today's standard. You can use the <noscript> tags for that.

Edited by Deirdre's Dad
Link to comment
Share on other sites

I found the culprit, see this code -

if (strpos($HTTP_USER_AGENT, 'Firefox') || strpos($HTTP_USER_AGENT, 'MSIE') || strpos($HTTP_USER_AGENT, 'Safari')){	$flag = 1;}if($flag==1){header("Content-type: text/html");}else {header("Content-type: application/vnd.wap.xhtml+xml");}

when i remove this code from the top of that php page, the javascripts work absolutely fine, but with this code added they dont work! they worked in html pages because that page dint have the above code.what above code does is catch the useragent and changes teh content type accordingly.(my site is basically a mobile site)Any ideas how to modify the above code to make the JS work?Thanks..

Link to comment
Share on other sites

Improper MIME type was my next guess, which is exactly why I wanted you to give links. There are tools for inspecting HTTP responses (like Firebug, Fiddler, etc.) which can help identify such problems.Get yourself one such tool, and look carefully at the user agent string in each browser, and react accordingly.Alternatively (and better so), do content negotiation with something like http_negotiate_content_type().

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...