Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php execute javascript

Status
Not open for further replies.

mwpc

Programmer
Apr 28, 2002
53
US
I want to use php to execute javascript and display the final results to the browser screen.

The objective is to remove the javascript from the source code so that search engine spiders will see the same text that the browser displays.


If you view-source on this page, you will only see the javascript. This is what the spiders see. I want the spiders to see the results displayed in the browser.

Thanks,
Mike

PHP code follows (sorry, tgml corrupted by in code):


<?php
echo'<html>


<script language=&quot;javascript&quot; >
var aqparams = new Array();
var aqThisUri = document.location.href;
function aqExtractQueryParams(qs)
{
var d = 1;
idx = qs.indexOf(\'?\');
if (idx != -1)
{
aqThisUri = qs.substring(0, idx);
query = qs.slice(idx+1);
query = query.replace(/%26/gi, &quot;&&quot;);
defs = query.split(\'&\');
prefix = &quot;?&quot;;
for (i=0;i<defs.length;i++)
{
if (defs != &quot;&quot;)
{
d = defs.split(\'=\');
aqparams[d[0]] = d[1];
if(d[0] != &quot;aqPage&quot;)
{
aqThisUri = aqThisUri + prefix + d[0] + &quot;=&quot; + d[1];
prefix = &quot;&&quot;;
}
}
}
}
}
aqExtractQueryParams(document.location.href);
function aqGetParam(s)
{
return aqparams;
}

var aqPageIndex = aqGetParam(&quot;aqpage&quot;);
if (aqPageIndex == null || aqPageIndex == &quot;undefined&quot;)
{
aqPageIndex = 1;
}
aqPageIndex = parseInt(aqPageIndex);
if (isNaN(aqPageIndex))
{
aqPageIndex = 1;
}
if (aqPageIndex < 0)
{
aqPageIndex = 1;
}
jobs = new Array ();
document.write(&quot;<scr&quot; + &quot;ipt language=\'javascript\' src=\' + aqPageIndex + &quot;&cat=Healthcare,+Practitioner+and+Technician&state=AR\'></scr&quot; + &quot;ipt>&quot;);
</script>
<link rel=stylesheet type=text/css href=&quot;<body bgcolor=&quot;#ffffFF&quot; class=background topmargin=&quot;0&quot; leftmargin=&quot;0&quot; marginheight=&quot;0&quot; marginwidth=&quot;0&quot;>

<table width=520 border=0 cellpadding=0 cellspacing=0>
<tr>
<td> <img src=&quot; width=15 height=40></td>
<td> <img src=&quot; </tr></table><ul>
<font class=header2>Healthcare Jobs</font> <font class=main>
    
<a href=&quot; target=&quot;_top&quot;>Return to Search Page</a>
</font>
<table cellpadding=5 cellspacing=3 border=0><script language=&quot;javascript&quot; >
if (jobs != null && jobs.length > 0) {
for (i = 0; i < jobs.length; i++) {
document.write(&quot;<tr><td>&quot;);
document.write(&quot;<TABLE style=\'border-color: white; border-style: solid; border-width: 0px;\' &quot;);
document.write(&quot;WIDTH=\'600\'&quot;);
document.write(&quot;BGCOLOR=\'white\' &quot;);
document.write(&quot;CELLSPACING=0 CELLPADDING=0>&quot;);
document.write(&quot;<tr><td width=\'100%\'>&quot;);
heading = jobs.heading;
if (jobs.heading.length > 128)
heading = jobs.heading.substring(0, 128) + &quot; ...&quot;;
document.write(&quot;<a href=\'&quot; + jobs.url + &quot;\'>&quot;);
document.write(&quot;<font face=\'Verdana,Trebuchet,sans-serif\' color=\'000099\' size=\'2\'><b>&quot; + heading + &quot;</b></font></a><br>&quot;);
desc = jobs.text;
if (jobs.text.length > 510)
desc = jobs.text.substring(0, 510) + &quot; ...&quot;;
document.write(&quot;<font face=\'Arial,sans-serif\' size=\'2\'> &quot; + desc + &quot;</font><br>&quot;);
if(jobs.location.length > 0) {
document.write(&quot;<font face=\'Verdana,Trebuchet,sans-serif\' size=\'2\'>&quot;);
document.write(&quot;Location: &quot; + jobs.location + &quot;</font><br>&quot;);
}
document.write(&quot;</td></tr>&quot;);
document.write(&quot;</table>&quot;);
document.write(&quot;</td></tr>&quot;);
}
if(aqPaginator != null) {
var aqRootUrl = aqThisUri;
if(aqRootUrl.indexOf(\'?\') == -1) {
aqRootUrl = aqRootUrl + &quot;?&quot;;
}
else {
aqRootUrl = aqRootUrl + &quot;&&quot;;
}
document.write(&quot;<tr><td align=left>&quot;);
if(aqPaginator[&quot;HasPrev&quot;] > 0 && aqPageIndex > 1) {
newPage = aqPageIndex - 1;
document.write(&quot;<a href=\&quot;&quot; + aqRootUrl + &quot;aqPage=&quot; + newPage + &quot;\&quot;>Prev</a>&quot;);
}
else {
document.write(&quot; &quot;);
}
if(aqPaginator[&quot;HasNext&quot;] > 0) {
if(aqPaginator[&quot;HasPrev&quot;] > 0 && aqPageIndex > 1) {
document.write(&quot; | &quot;);
}
newPage = aqPageIndex + 1;
document.write(&quot;<a href=\&quot;&quot; + aqRootUrl + &quot;aqPage=&quot; + newPage + &quot;\&quot;>Next</a>&quot;);
}
if(aqPaginator[&quot;HasNext&quot;] > 0 || aqPaginator[&quot;HasPrev&quot;] > 0) {
document.write(&quot; | &quot;);
}
document.write(&quot;<a href=\' + aqPageIndex + &quot;&cat=Healthcare,+Practitioner+and+Technician&state=AR \'>More Results (&quot; + aqNumJobs + &quot; jobs)</a>&quot;);
document.write(&quot;</td></tr>&quot;);
}
}
</script>
<tr><td width=\'100%\'><b><font size=\'-3\'><font color=\'#A0A0A0\'>Powered by</font> <a href=\' color=\'#000000\'>Access</font><font color=\'#d88f1e\'>Query</font></a></font></b></td></tr></table>
</html>
';
 
yeah, thats the only way to avoid JS in the view source...

Known is handfull, Unknown is worldfull
 
One more comment:
Besides giving the spider somthing to relate to the PHP solution also has the advantage that ALL visitors, with or without JavaScript capabilities, have access to your site. There are still people out there that turn JavaScript off or use some intermediary, obsolete brwosing software.
 
This particular search is run on a remote server (accessquery.com) using .NET protocols. I believe the javascript is required for the search to function.

Does anybody grasp how to pass the required values to the microsoft server using PHP rather than javascript?
 
I think this requires some clever javascript - u can run your own javascript function on the returned document that returns the actual Document html when the scripts on the page are executed maybe something like &quot;document.body&quot; in javascript may return all the contents withing the body tags - I know createTextRange() works in JScript for IE browswers - u can then extract the needed info from within the tags and submit this thru a form on the same page to your PHP document, all using javascript.

Sorry, there's no way I know of for you to do this w/o using javascript which defeats your automated spider I know.

Looking at the site I can tell you what they did is put in LINK tags to javascript scripts which just contain the TEXT your looking for but even then it's all chopped up with '+' signs to concate them together using javascript. So what you could do is get your PHP page to sniff out the Link tags and then Obtain those script pages that are linked to -> now all you have to do is delete all the instances of '+' and put the words together and then u need to eliminate the <script> tags they put around the text also - a very customized solution.


Rocco is the BOY!!

SHUT YOUR LIPS...
ROCCOsm.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top