Visualforce page that calls another Visualforce page upon confirming from javascript.
Visualforce Page:
<apex:page standardController="Account">
<apex:form>
<apex:pageBlock>
<apex:commandButton value="Open VF Page" onclick="OpenVFPage()"/>
</apex:pageBlock>
<script>
function OpenVFPage(){
var isConfirm = confirm('Do you want to open a new Visualforce Page?');
if(isConfirm)
window.open('/apex/YourVisualForcePage');
}
</script>
</apex:form>
</apex:page>
Similarly, if you want to open a visualforce page from a custom button using javascript then use following piece of code.
{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}
var isConfirm = confirm('Do you want to open new Visualforce Page?');
if(isConfirm){
window.parent.location.href="/apex/YourVisualforcePage";
}
JSON (JavaScript Object Notation) is a lightweight and text-based data-interchange format. Supports with UTF-8 and date-time information in ISO8601 format. It uses string value pairs for storing data.
Basically it is used to transmit data between a browser and a server. When exchanging data between a browser and a server, the data can only be text. JSON is text, and we can convert any JavaScript object into JSON, and send JSON to the server.
Sometimes we need to pass variables from apex to javascript. Here is an example to pass variables from apex to javascript. In below example I’m invoking one apex method using action function. In the apex method I’m defining the apex variable value. On complete of action function I’m invoking one javascript method and using the apex variable in the javascript method.