• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 432
  • Last Modified:

Run JavaScript Function Remotely with PHP

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
EMB01
Asked:
EMB01
1 Solution
 
striker46Commented:
PHP is server side, JS is client side. You cannot run JS directly in PHP.
0
 
palanee83Commented:
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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now