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
RDeepaRDeepa 

How to open Multiple windows on click of a button?

Hi,


There is a requirement to open 3 windows on click of a button. This is the way which I tried:

1. I wrote 0nclick javascript for a button. I am getting the selected record ids and passing it to the VF page with the help of hidden elements

f1=document.createElement('form');

f1.action='https://c.ap1.visual.force.com/apex/page0';

f1.method='post';

f1.target='thatframe';

ch1=document.createElement('input');

ch1.value=IdsList;//Adding the Ids

 2. I am separating the record Ids in the controller of the VF page page0. I have used InputHidden to get the Ids from controller.

function funcload(){
var SampId1=SampIds1.value;
var SampId2=SampIds2.value;
var SampId3=SampId23.value;
if(SampId1!=""){
f1=document.createElement('form'); f1.action='https://c.ap1.visual.force.com/apex/page1';
f1.method='post';
f1.target='thatframe';
ch1=document.createElement('input');
ch1.value=SampId1;
}
if(SampId2!=""){
f2=document.createElement('form'); f2.action='https://c.ap1.visual.force.com/apex/page2';
.... ch2.value=SampId2;
}
if(SampId3!=""){
f3=document.createElement('form'); f3.action='https://c.ap1.visual.force.com/apex/page3';
... ch3.value=SampId3;
}
}
<apex:form >
<apex:inputHidden value="{!SampleIds1}" id="SampId1"/>
<apex:inputHidden value="{!SampleIds2}" id="SampId2"/>
<apex:inputHidden value="{!SampleIds3}" id="SampId3"/> <script>SampIds1=document.getElementById('{!$Component.SampId1}');</script> <script>SampIds2=document.getElementById('{!$Component.SampId2}');</script> <script>SampIds3=document.getElementById('{!$Component.SampId3}');</script> </apex:form>

Behaviour of this code is: It is considering the last url, only one window is opening at a time (with the last url). I am getting the alert messages, if i add inside the IF conditions. But the pages are not getting opened.

Can anyone help me on this issue?

Regards,
Deepa

 

 

prageethprageeth

You can use window.open() method several times to open multiple windows.

 

<apex:page>

<script>

function show() {

window.open('http://www.google.com');

window.open('http://www.yahoo.com');

window.open('http://www.example.com');

}

</script>

<apex:form>

<apex:commandButton value="Go" onclick="show();"/>

</apex:form>

</apex:page> 

 

 

RDeepaRDeepa

Thanks Prageeth.

 

I tried with window.open. Window.open will not be helpful when we want to pass hidden elements. I tried by assigning the target as '_blank'. I am able to pass the hidden elements in the url and open multiple windows.