Solved

Run JavaScript Function Remotely with PHP

Posted on 2009-04-14
2
412 Views
Last Modified: 2012-05-06
If I have a PHP script that loads the content of an external HTML page, for instance:
fopen("http://www.example.com", "r");

Is it possible to execute JavaScript commands that exist on that page? For example, if a button exists on that page like:
<a href="" onclick="javascript...">Link</a>

Could I run that JavaScript from my PHP script?
0
Comment
Question by:EMB01
2 Comments
 
LVL 5

Expert Comment

by:striker46
ID: 24138754
PHP is server side, JS is client side. You cannot run JS directly in PHP.
0
 
LVL 5

Accepted Solution

by:
palanee83 earned 500 total points
ID: 24156736
Hi,

Yes its possible to run the java script which is available in the remote server  from PHP. But the content of remote URL should be printed before calling javascript function either using fopen() or file_get_content()

ex:
<?php
echo file_get_content("http://www.example.com");
 ?>

If the remote script is is having only JS code then u can directly use  URL in the  'SRC'  attribute of script tag to load the JS function in to the current scope.

<script src="http://www.example.com" > </src>




0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Help with PHP 13 27
selector:validator cookies 4 30
PHP delete contents of file- before writing to it 6 22
WordPress 8 28
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question