Jump to content

want to call javascript fucntion in webpage


bhavin12300

Recommended Posts

hi.

till now i have been working in vb.net. Now i have move to php for developing.

 

I am using curl to get webpage.

Now this page has some javascript function in it.

This function is called when i click on link on that page if i visit this page on webbrowser.

 

As i have html code of that page in my php scrip.but i want to automate clicking that link on that page means i want to call that javascript function in it.

is it possible ???

please tell me what do i do??

 

 

 

Link to comment
Share on other sites

you can't call the js function in php the only way is to create a function in php that does what the js function did like this

function js_function($url){
//do what the js did to the url
return $url;
}

the only other way is to load the page with the cURL request and have the user press the link so the javascript will run in the users browser

 

Scott.

 

Link to comment
Share on other sites

hi.

till now i have been working in vb.net. Now i have move to php for developing.

 

I am using curl to get webpage.

Now this page has some javascript function in it.

This function is called when i click on link on that page if i visit this page on webbrowser.

 

As i have html code of that page in my php scrip.but i want to automate clicking that link on that page means i want to call that javascript function in it.

is it possible ???

please tell me what do i do??

 

I have yet to find php code that compiles JavaScript. That's like asking vb to compile flash. What does the JavaScript function do anyways? For example, are you grabbing the content from the remote site and presenting the code to your webpage to be viewed in a browser as well?

Link to comment
Share on other sites

you can't call the js function in php the only way is to create a function in php that does what the js function did like this

function js_function($url){
//do what the js did to the url
return $url;
}

the only other way is to load the page with the cURL request and have the user press the link so the javascript will run in the users browser

 

Scott.

 

 

this is what i am doing.exactly.

i have load page in my php page.now want to click on click on it which call that JavaScript function.

can you guide me how to click that link?

Link to comment
Share on other sites

 

I have yet to find php code that compiles JavaScript. That's like asking vb to compile flash. What does the JavaScript function do anyways? For example, are you grabbing the content from the remote site and presenting the code to your webpage to be viewed in a browser as well?

Hope you what i am in need of from above reply.

Link to comment
Share on other sites

I think you might be a little confused or I am.

If your trying to get php to exicute the javascript function that cant be done.  PHP is exicuted before the browser even sees anything javascript is run at the server.

If your trying to get PHP to do what the JavaScript was doing then your going to have to post the entire JavaScript function.

Link to comment
Share on other sites

I think you might be a little confused or I am.

If your trying to get php to exicute the javascript function that cant be done.  PHP is exicuted before the browser even sees anything javascript is run at the server.

If your trying to get PHP to do what the JavaScript was doing then your going to have to post the entire JavaScript function.

sir,

as i have mention above.i am displaying webpage from my php scrip using curl.

now on this page there is one link which when clicked call JavaScript function which i have mention in my last to second reply.

i want to call this JavaScript function automatically once my page loaded on browser through curl.

Link to comment
Share on other sites

then you want to find the line with the <bdoy> tag and add in an onLoad i suggest:

<?php
$lines = expode('\n', $data);
foreach($lines as $line)
{
   if(preg_match('<body', $line))
 {
	if(preg_match('><', $line)) //This is not required but some bad devs will do <body...><newTag... and we'll want to catch that if the site you are taking from does not do that then, remove this condition.
	 {
		preg_split('/>[abcdefghijklmnopqrstuvwxyz0123456789\t]*</i', $line);
	 }
	$line = preg_replace('>', '', $line) . ' onLoad="functionName >";';
    }
}
?>

This need improvement and is not tested.

Link to comment
Share on other sites

if you set a onload="js_function()" in the <body> tag so it looks like this <body onload="js_function()"> when the page is fully loaded images and everything (except flash i think) it will run js_function().

i think a better way than all those preg_replace() you could just use str_replace()

echo str_replace("<body>","<body onload=\"js_function()\">",$html_from_curl);

 

Scott.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.