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

Visualforce and Javascript
Hi Friends,
I have visual force tab in salesforce.So when somebody navigates away from the tab ,for example,clicks on some other tab then he should see a dialog box which says that,Are u sure that you want to naviage away from this page?
Below given code does not belong to me.However,it does run and show dialog box with the message:-
This page is asking you to confirm that you want to leave - data you have entered may not be saved
How do I override this message or show my own message.
public class wrap2co {
String searchSolutionText;
List<List<sObject>> tresults;
List<Solution> results;
public String getSearchSolutionText() {
return searchSolutionText;
}
public void setSearchSolutionText(String s) {
searchSolutionText = s;
}
public List<Solution> getResults() {
return results;
}
public PageReference doSearch() {
tresults = [FIND :searchSolutionText RETURNING Solution(SolutionName, SolutionNote, CreatedDate)];
results = (List<Solution>)tresults[0];
return null;
}
}
<apex:page controller="wrap2co">
<script LANGUAGE="JavaScript1.2" TYPE="text/javascript">
function unloadMessage(){
message = "Wait! You haven't finished."
return message;
}
function setBunload(on){
window.onbeforeunload = (on)? unloadMessage : null;
}
setBunload(true);
</script>
<apex:form >
<apex:pageBlock >
<apex:pageblockButtons >
<apex:commandButton action="{!doSearch}" value="Search" rerender="output"></apex:commandButton>
</apex:pageblockButtons>
<apex:inputText value="{!SearchSolutionText}"></apex:inputText>
</apex:pageBlock>
<apex:outputPanel >
<apex:pageBlock >
<apex:pageblockTable value="{!results}" var="v">
<apex:column value="{!v.SolutionName}"/>
<apex:column value="{!v.SolutionNote}"/>
<apex:column value="{!v.CreatedDate}"/>
</apex:pageblockTable>
</apex:pageBlock>
</apex:outputPanel>
</apex:form>
</apex:page>
Thanks,
Trick
If you set the value of the message in your controller to a variable do:
<script LANGUAGE="JavaScript1.2" TYPE="text/javascript">
function unloadMessage(){
message = '{!VARNAME}';
return message;
}
or of you hardcode it in the java just change the text
<script LANGUAGE="JavaScript1.2" TYPE="text/javascript">
function unloadMessage(){
message = "YOUR Message"
return message;
}