bhavin12300 Posted August 2, 2008 Share Posted August 2, 2008 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 https://forums.phpfreaks.com/topic/117804-want-to-call-javascript-fucntion-in-webpage/ Share on other sites More sharing options...
ratcateme Posted August 2, 2008 Share Posted August 2, 2008 you would have to recreate the the javascript function in php then pass the vars it needs from the html to it to get the output Scott. Link to comment https://forums.phpfreaks.com/topic/117804-want-to-call-javascript-fucntion-in-webpage/#findComment-605926 Share on other sites More sharing options...
bhavin12300 Posted August 2, 2008 Author Share Posted August 2, 2008 But my web page source code is in string. how can i call JavaScript function in it?can you tell me how to do that? Link to comment https://forums.phpfreaks.com/topic/117804-want-to-call-javascript-fucntion-in-webpage/#findComment-605928 Share on other sites More sharing options...
ratcateme Posted August 2, 2008 Share Posted August 2, 2008 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 https://forums.phpfreaks.com/topic/117804-want-to-call-javascript-fucntion-in-webpage/#findComment-605933 Share on other sites More sharing options...
bretticus Posted August 2, 2008 Share Posted August 2, 2008 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 https://forums.phpfreaks.com/topic/117804-want-to-call-javascript-fucntion-in-webpage/#findComment-605935 Share on other sites More sharing options...
bhavin12300 Posted August 2, 2008 Author Share Posted August 2, 2008 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 https://forums.phpfreaks.com/topic/117804-want-to-call-javascript-fucntion-in-webpage/#findComment-605937 Share on other sites More sharing options...
bhavin12300 Posted August 2, 2008 Author Share Posted August 2, 2008 This is onlick attribute for that link onclick="_singleDelete(function() {_doDelete(document.deleteForm, 94688945, 94688945, 1216466854)}); return false;" can you tell what which code i should as to call this function? Link to comment https://forums.phpfreaks.com/topic/117804-want-to-call-javascript-fucntion-in-webpage/#findComment-605940 Share on other sites More sharing options...
bhavin12300 Posted August 2, 2008 Author Share Posted August 2, 2008 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 https://forums.phpfreaks.com/topic/117804-want-to-call-javascript-fucntion-in-webpage/#findComment-605946 Share on other sites More sharing options...
unkwntech Posted August 2, 2008 Share Posted August 2, 2008 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 https://forums.phpfreaks.com/topic/117804-want-to-call-javascript-fucntion-in-webpage/#findComment-605958 Share on other sites More sharing options...
bhavin12300 Posted August 2, 2008 Author Share Posted August 2, 2008 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 https://forums.phpfreaks.com/topic/117804-want-to-call-javascript-fucntion-in-webpage/#findComment-605972 Share on other sites More sharing options...
ratcateme Posted August 2, 2008 Share Posted August 2, 2008 so you want to run the js function on the clients browser when they have loaded the page? Scott. Link to comment https://forums.phpfreaks.com/topic/117804-want-to-call-javascript-fucntion-in-webpage/#findComment-605975 Share on other sites More sharing options...
unkwntech Posted August 2, 2008 Share Posted August 2, 2008 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 https://forums.phpfreaks.com/topic/117804-want-to-call-javascript-fucntion-in-webpage/#findComment-605976 Share on other sites More sharing options...
bhavin12300 Posted August 2, 2008 Author Share Posted August 2, 2008 so you want to run the js function on the clients browser when they have loaded the page? Scott. yes and i don't have definition of that function.what i know is function call as i have stated in my previous reply. Link to comment https://forums.phpfreaks.com/topic/117804-want-to-call-javascript-fucntion-in-webpage/#findComment-606164 Share on other sites More sharing options...
bhavin12300 Posted August 2, 2008 Author Share Posted August 2, 2008 then you want to find the line with the <bdoy> tag and add in an onLoad i suggest: This need improvement and is not tested. sir, i am not getting what you want to say.please can you justify your comments in bit detail?? Link to comment https://forums.phpfreaks.com/topic/117804-want-to-call-javascript-fucntion-in-webpage/#findComment-606172 Share on other sites More sharing options...
ratcateme Posted August 2, 2008 Share Posted August 2, 2008 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 https://forums.phpfreaks.com/topic/117804-want-to-call-javascript-fucntion-in-webpage/#findComment-606326 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.