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
Dhanamjaya PaidipatDhanamjaya Paidipat 

custom button with java script

Hi Team,
I have develpoed below JS but it's not working , when i am trying to click a custom button getting an unexpected token alert.
Kindly help out on this.

<script type="text/javascript">
            var newWin;
            function openingwindow()
            {              
               alert('cmng to loop..');
               newWin=window.open("https://api1.cloudagent.in/CAServices/AgentManualDial.php?api_key=KKf490fbb75a904b31bcbe7ddb7a681919&Country={!Lead.Country__c}&Phone={!Lead.Phone}",'width=100,height=100');
               alert(setTimeout(function(){newWin.close()}, 30000));
               setTimeout(function(){newWin.close()}, 30000);
               alert('closed..');
            }
                       
    </script>
Ashish Arun WaghmareAshish Arun Waghmare
Hi Dhanamjaya ,

Please try below code  it should work

{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")} 


var newWin;

 alert('cmng to loop..');
 
newWin = window.open("https://api1.cloudagent.in/CAServices/AgentManualDial.php?
api_key=KKf490fbb75a904b31bcbe7ddb7a681919&Country={!Lead.Country__c}&Phone={!Lead.Phone}",'width=100,height=100');

   alert(setTimeout(function(){newWin.close()}, 30000));
   setTimeout(function(){newWin.close()}, 30000);
   alert('closed..');


Hope this hepls !!!
 
Dhanamjaya PaidipatDhanamjaya Paidipat
Hi Arun,
After added above still geeting the same issue please find error User-added imageimage.
Maharajan CMaharajan C
Hi Dhanamjaya,

Please check the link (i.e the URL you are forming ) you have used in the window.open method because i have the tried the below codes it's working fine:

=======================
{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")} 

{!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")} 

var newWin; 

alert('cmng to loop..'); 

newWin = window.open("https://www.google.com",'width=100,height=100'); 

alert(setTimeout(function(){newWin.close()}, 30000)); 
setTimeout(function(){newWin.close()}, 30000); 
alert('closed..');

======================

Used My VF Page in URL:

{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")} 

{!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")} 

var newWin; 

alert('cmng to loop..'); 

newWin = window.open("https://rajaccountgeolocationapp-dev-ed--c.ap6.visual.force.com/apex/AccountDisplaypopup?id={!Account.Id}",'width=1000,height=900'); 

//alert(newWin); 

alert(setTimeout(function(){newWin.close()}, 30000)); 
setTimeout(function(){newWin.close()}, 30000); 
alert('closed..');


=======================

Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!


Thanks,
Maharajan.C
Ashish Arun WaghmareAshish Arun Waghmare
Hi Dhanamjaya, 

The URL which you are forming in window.open  - form it in notepad and then just run in the browser check if it works .. once that URL works use it in window.open , my code will work.

You are forming the URL incorrectly !!!

Hope this helps !!!