You need to sign in to do that
Don't have an account?

Navigate from VF page to google search
hi,
I have a VF Page it contains search input search box and search button.If i entered any value in search text box like "Car" it should redirect from VF page to the google search page with keyword name and displays results regarding cars.
Is it possible using VF page.
Please suggest me how to approach...
Thank you.
I have a VF Page it contains search input search box and search button.If i entered any value in search text box like "Car" it should redirect from VF page to the google search page with keyword name and displays results regarding cars.
Is it possible using VF page.
Please suggest me how to approach...
Thank you.
Either you can use action method like below .
Or you have add reRender in action function component to call the method .
Thnaks
Manoj
All Answers
https://www.google.co.uk/search?q=visualforce
So you can either build a pagereference server side and redirect, or change the window.location via JavaScript.
You can get the search text value in your controller by assigning a getter setter ,assume
public string searchText{get;set;}
Once you will click on the button it should call method and that method shound have return type PageRefrenece .
Finally in page Reference you need to pass the URl like below
https://www.google.co.in/search?newwindow=1&site=&source=hp&q=+searchText
If you need any help on pageReference Please check below link .
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_system_pagereference.htm
Thnaks
Manoj
Thanks for your reply bob & Manoj,
Below is my code
VF Page:
<apex:page controller="Googlequery">
<script type="text/javascript">
function jsfind()
{
callgoogle();
}
</script>
<apex:pagemessages/>
<apex:form>
<apex:actionFunction name="callgoogle" action="{!searchpage}"/>
<apex:pageBlock>
<apex:outputLabel>Query Google</apex:outputLabel>
<apex:inputText value="{!qry}"/>
</apex:pageBlock>
<apex:commandButton value="Search keyword" onclick="jsfind()"/>
</apex:form>
</apex:page>
Apex Class :
public class Googlequery{
public string qry{get;set;}
public pagereference searchpage(){
Pagereference pg=new pagereference('http://www.google.com/search?q='+qry);
pg.setRedirect(true);
return pg;
}
}
i tried using javascript but when i click on Search Keyword button i dont get changes in my visualforce page.
How to resolve using javascript.
Thanks in advance.
Either you can use action method like below .
Or you have add reRender in action function component to call the method .
Thnaks
Manoj
The above code does not redirect into google search page.Can you explain what mistake i did there??>
thanks,
deepak
The above code is absolutely correct.Can you please explain me what error you are exactly facing?
When i search any keyword like "Car" in input text box.It simply loads with empty page in salesforce.How can i approach to redirect into google search page..
Please help me,
Thanks,
Deepak
Have you tested the above code ,or have you added the reRender in your action Function . I have tested in my dev org it is working fine .
Please let me the error you are getting .
I removed reRender and its working fine. And i have one more modification is that i need to open that google search page in a new window.
Thanks,
Deepak
Hi Deepak,
Please check the following code:
<apex:page controller="Googlequery" id="pg">
<script>
function redirectToGoogle(){
var a=document.getElementById('pg:frm:pg:input').value;
window.parent.open('http://www.google.com/search?q='+a);
}
</script>
<apex:form id="frm">
<apex:pageBlock id="pg">
<apex:outputLabel id="op">Query Google</apex:outputLabel>
<apex:inputText value="{!qry}" id="input"/>
</apex:pageBlock>
<apex:commandButton value="Search keyword" onclick="redirectToGoogle();" id="cmd"/>
</apex:form>
</apex:page>
This code will make you open google search in new window.
Dhriti Moulick..Your Code Really worked..Thanks to everyone..
Manojj can you provide me a test class in order to pass the controller from Sandbox to Production?
Here is my Controller
public class Googlequery{
public string qry{get;set;}
public pagereference searchpage(){
Pagereference pg=new pagereference('https://docs.google.com'+qry);
pg.setRedirect(true);
return pg;
}
public pagereference searchpage1(){
Pagereference pg=new pagereference('https://docs.google.com/spreadsheets'+qry);
pg.setRedirect(true);
return pg;
}
}
------------------------------------
VF Page
<apex:page controller="Googlequery">
<apex:pagemessages />
<apex:form >
<apex:pageBlock >
<apex:outputLabel >Google Docs</apex:outputLabel>
</apex:pageBlock>
<apex:commandButton value="Cyprus Live" action="{!searchpage}"/>
<apex:commandButton value="UK Live" action="{!searchpage1}"/> </apex:form>
</apex:page>