JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 27th, 2001, 05:37 PM
Neole Neole is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Posts: 5 Neole User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Executing javascript from ermote php file

I need to use a remote php script to execute some javascript. I'm using a line on my pages -
<script language="jscript" src="http://www.mydomain.com/file.php"></script>

How do I make the remote php script execute a javascript, or pass on the javascript.js file to the calling html document? (It is a bit like a cgi counter where the counter is linked to a cgi file which passes on an image, in this case I want to pass on a javascript file.)

Reply With Quote
  #2  
Old May 27th, 2001, 05:53 PM
sparki sparki is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Location: Sydney
Posts: 41 sparki User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
A php script will never execute javascripts. It's your browser that executes javascripts. You may use something like this;

<script language="jscript" src="http://www.mydomain.com/path/javascript.js"></script>

Reply With Quote
  #3  
Old May 27th, 2001, 06:02 PM
Neole Neole is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Posts: 5 Neole User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
No, what I want to do is use the php file to track the referring page and the number of visits. When this function is called from an html page -

<script language="jscript" src="http://www.mydomain.com/file.php"></script>

- the php file checks up some info from the mysql database and depending on that I want it to pass on different javascript (js) files to the html page. Then the browser will excute the js file. How do I do that?

Reply With Quote
  #4  
Old May 28th, 2001, 08:04 PM
sparki sparki is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Location: Sydney
Posts: 41 sparki User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
Oh I see. I am not sure how you are going to do it from a plain html file unless you use SSI. But I don't believe the code;
<script language="jscript" src="http://www.mydomain.com/file.php"></script>
will execute the php file and pass the result to your browser.

Best approach maybe to use a php file instead of html. You can use "file" command to get the result from http://www.mydomain.com/file.php like;

$result=file("http://www.mydomain.com/file.php");

Good luck!

Reply With Quote
  #5  
Old May 28th, 2001, 10:51 PM
rycamor rycamor is offline
Gödelian monster
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 1999
Location: Central Florida, USA
Posts: 2,306 rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 6 h 42 m 51 sec
Reputation Power: 60
Of course <script language="jscript" src="http://www.mydomain.com/file.php"></script> would execute PHP and pass the results back to the browser. Even though it is inside a <script> tag, that PHP code is being requested by the browser, so it will be parsed by the server first. (otherwise, we would have a big security hole, wouldn't we?)

Javascript and PHP operate in two completely different realms. PHP doesn't have anything to do with the browser, other than the fact that it can receive certain browser variables. It operates in server space only. Client-side Javascript operates in browser space only. So it's completely possible to have a script that is requested by the browser as a Javascript file, but is executed by the server first, upon which you can output any valid Javascript code you want, to be processed by the browser.

If for example, you want to conditionally use either one external .js file or another, depending on any combination of conditions you want (such as browser type or version), you could simply do:

PHP Code:
<?php

if(condition....etc...){
   include(
"jsfile1.js");
}

elseif(
condition 2 ...etc...){
   include(
"jsfile2.js");
}

else{
include(
"jsfile3.js");
}


or, you could actually turn server-side variables into client-side ones, just by
PHP Code:
<?php

echo "variable1 = \"$variable1\";\n";
echo 
"variable2 = \"" $variable2a $variable2b "\";\n";

?>
__________________
The real n-tier system:

FreeBSD -> PostgreSQL -> [any_language] -> Apache -> Mozilla/XUL

Amazon wishlist -- rycamor (at) gmail.com

Reply With Quote
  #6  
Old May 29th, 2001, 02:55 AM
sparki sparki is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Location: Sydney
Posts: 41 sparki User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
Rycamor, I don't think your first example will work. PHP will include whatever the comtents and possibly produces some error because of javascript syntax.

It may work if you echo the contents of js files.

Anyway, I learnt something. Thanks!!

Last edited by sparki : May 29th, 2001 at 02:57 AM.

Reply With Quote
  #7  
Old May 29th, 2001, 04:19 AM
Neole Neole is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Posts: 5 Neole User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi Sparky,

The <script language="jscript" src="http://www.mydomain.com/file.php"></script> line is working perfectly well with the 'echo' command giving the contents of the js.

Hi Rycamor,

The include command was exactly what I was looking for. Hopefully I can use an external encoded js file now. Thanks!

Reply With Quote
  #8  
Old May 29th, 2001, 10:00 AM
rycamor rycamor is offline
Gödelian monster
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 1999
Location: Central Florida, USA
Posts: 2,306 rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 6 h 42 m 51 sec
Reputation Power: 60
Sparki,

When PHP includes an external file, it drops out of PHP parsing mode for that file, unless the file has a <?php tag in it. So including Javascript will be absolutely no problem for PHP, the same as including HTML.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Executing javascript from ermote php file

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap