function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
trick.ax1374trick.ax1374 

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

Starz26Starz26

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;
}

trictric
Hi Starz, Thanks for your reply. I have looked at your second option.My code has Javascript statements in which message have been hard coded. However,it doesn't work in Firefox,It does work in Internet explorer and Chrome. It does not work in firefox because of known bug. My another question is :-For example,I have visual force tab.My visual force page has been associated to visual force page.Everything is working fine,only problem is when I click on tab named test1 twice ,It shows me a message twice.It should not show any message when I click on the test1 tab.It should only show when I navigate from this tab. Any idea what can be done about this.? Do we have tab events in visualforce for the visual force tab?