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
eswarsfeswarsf 

multiple windows for Visualforce Page on button click

Hi,

I have a visualforce page which will open whenever user clicks on button.if I am clicking on that button multiple times,multiple visualForce windows are opening.

Kindly let me know is there ay way to restrict only one time,I mean if already VF window is opened,if I am clicking multiple times that button now it should show me already opened VF window.

 

Thanks

Navatar_DbSupNavatar_DbSup

Hi,

 

You can stop multiple windows opening when a button is click by using the javascript on both the page parent and child windows respectively

 

You can use the below code as a reference

 

Vf First page 

<apex:page >
<script>
var win1=null;
function chkwinopen()
{
   if(win1==null)
    {
      win1=window.open('/apex/callonbutton','','width=200,height=100');
        win1.focus();
        win1=true;
    }
    else
	{
		alert('window alleray open');
	}
	return false;
} 
</script>
<apex:form >
  
  <Apex:commandButton value="open" onclick=" return chkwinopen()"/>
  
  </apex:form>
</apex:page>

Vf Second page 

<apex:page >
<script>
	window.onbeforeunload=function() {window.parent.parent.opener.win1=null;}
</script>
</apex:page>

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.