Solved

Run JavaScript Function Remotely with PHP

Posted on 2009-04-14
2
409 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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now