Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / May 2006



Tip: Looking for answers? Try searching our database.

IE Problem : Dynamic Javascript in PHP constructor

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
pulkit.gaur@gmail.com - 30 May 2006 12:53 GMT
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 ?
Erwin Moller - 30 May 2006 13:34 GMT
> Hi all ,
>
[quoted text clipped - 12 lines]
>
> 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
pulkit.gaur@gmail.com - 30 May 2006 16:14 GMT
Thanks Erwin,

But i already tried this .
Thomas 'PointedEars' Lahn - 30 May 2006 23:20 GMT
> Thanks Erwin,
>
> But i already tried this .

Tried what?  <URL:http://jibbering.com/faq/>

PointedEars
Signature

But he had not that supreme gift of the artist, the knowledge of
when to stop.
 -- Sherlock Holmes in Sir Arthur Conan Doyle's
    "The Adventure of the Norwood Builder"

Lasse Reichstein Nielsen - 30 May 2006 23:42 GMT
> But i already tried this .

(Tried what? Please quote an appropriate part of what you are responding to).

Anyway, then the problem is probably somewhere else on the page. Can
you give a link to the page that is served so we can see for ourselves?

/L
Signature

Lasse Reichstein Nielsen  -  lrn@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
 'Faith without judgement merely degrades the spirit divine.'

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.