+ Start a Discussion
Mitchell McLaughlin 1Mitchell McLaughlin 1 

Javascript onClick button

Hello - I'm using this java script on my button to make sure the address is filled out... But since i started using window.open it opens this new page in a new tab.
I want it to be the same tab and just go to the new page like before. Is there a different function i should be using to open this?
 
{!REQUIRESCRIPT("/soap/ajax/21.0/connection.js")} 

var leadAddress = '{!Lead.Street}'; 
var leadCity = '{!Lead.City}'; 
var leadState = '{!Lead.State}'; 
var leadCountry = '{!Lead.Country}'; 
var leadZip = '{!Lead.PostalCode}'; 

if(leadAddress == null || leadAddress == ''){ 
alert('Please enter a valid Street Address along with the City, State/Province, Zip/Postal Code and Country before clicking on this button.'); 
} 
else if(leadCity == null || leadCity == ''){ 
alert('Please enter a valid Street Address along with the City, State/Province, Zip/Postal Code and Country before clicking on this button.'); 
} 
else if(leadState == null || leadState == ''){ 
alert('Please enter a valid Street Address along with the City, State/Province, Zip/Postal Code and Country before clicking on this button.'); 
} 
else if(leadCountry == null || leadCountry == ''){ 
alert('Please enter a valid Street Address along with the City, State/Province, Zip/Postal Code and Country before clicking on this button.'); 
} 
else if(leadZip == null || leadZip == ''){ 
alert('Please enter a valid Street Address along with the City, State/Province, Zip/Postal Code and Country before clicking on this button.'); 
} 
else{ 
var urlStr = '/a0J/e?' 
+ 'CF00Nj00000091TUH={!Lead.FirstName &" "& Lead.LastName }' 
+ '&CF00Nj00000091TUH_lkid={!Lead.Id}' 
+ '&retURL=%2F{!Lead.Id}' 
+ '&saveURL=%2F{!Lead.Id}' 
+ '&RecordType=012j0000000pfbL' 
+ '&ent=01Ij0000001EVex' 
+ '&00Nj00000091TU6={!Lead.Company}' 
+ '&00Nj00000091TUQ=Pending'; 

window.open(urlStr); 

}



Thanks!
Best Answer chosen by Mitchell McLaughlin 1
Temoc MunozTemoc Munoz
Hi Mitchell.

This behavior is browser dependent and may work for some browsers only.
 
window.open("www.youraddress.com","_self")

or

location.href = "http://youraddress.com";

 

All Answers

Prem Anandh 1Prem Anandh 1
Hi Mitchell, 

Please try with below code and let me know if you are facing any issues
window.open(urlStr, '_blank');

Thanks,
Prem Anandh
Mitchell McLaughlin 1Mitchell McLaughlin 1
It still opens a new tab. I want it to be the same tab and just go to the new page. Not fixed yet. any other ideas? :/
Prem Anandh 1Prem Anandh 1
Please see below example:

            window.location.href = urlStr;
 
<apex:page>
    
    <input type="button" value="Open New Tab" onClick="openSameTab();" />
    
    <script>
        function openSameTab()
        {
            varURL = "http://www.google.com";
            window.location.href = varURL;
        }
    </script>

</apex:page>

 
Temoc MunozTemoc Munoz
Hi Mitchell.

This behavior is browser dependent and may work for some browsers only.
 
window.open("www.youraddress.com","_self")

or

location.href = "http://youraddress.com";

 
This was selected as the best answer
Mitchell McLaughlin 1Mitchell McLaughlin 1
Fixed! Thanks!!
Temoc MunozTemoc Munoz
Nice!!