pu*********@gmail.com wrote:
Hi all ,
I have a PHP class.
In the constructor method i use the following code :
constructor func .......
{
echo "<script type=\"text/javascript\">";
echo "alert('hi');
echo "</script>";
}
This works perfectly fine in Mozilla ..
But .. seems .. IE can't run this code ..
Can you tell me the reason and how to fix it ?
Hi
This has nothing to do with PHP.
The browser receives just HTML from a server and couldn't care less if that
is produced by PHP, VB, Perl, blue midgets, or just random noise.
So if you wonder why some piece of HTML doesn't work, look at the source of
the page first.
In your case you will find:
<script type="text/javascript">alert('hi');</script>
That should work in principle.
Maybe IE doesn't like to receive all commands on 1 line?
Maybe Javascript is disabled?
Maybe an earlier error on the page is causing this?
Hard to say.
I would start by adding \n after each echo.
Off topic: Why echo all the lines and give yourself a hard time?
This is perfectly legal in PHP and keeps the suff readable for you too:
constructor func .......
{
// just jump to HTML literal mode:
?>
<script type="text/javascript">
alert('hi');
</script>
<?php
// back in PHP
}
Regards,
Erwin Moller