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
Naomi HarmonNaomi Harmon 

Javascript launches pop-up but window.open function will not work for button

Hey guys,

I found code for a cool pop-up window that looks and works beautifully. So I have a button on the Contact that executes the following Javascript:

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

specialcare = "{!Contact.Special_Care_Comments__c}";
contact = "{!Contact.Id}";
dates = new Date();

function insertScript(script){ 
	var targetNode = document.createElement('div');	//	construct div for script injection 
	document.body.appendChild(targetNode); 
	try {
		var el = document.createElement('script');
			el.type="text/javascript";
			el.innerHTML = script;
		targetNode.appendChild(el); 
	} catch (e){ 
		var el = document.createElement('span'); 
		targetNode.appendChild(el); 
		el.innerHTML = "<br /><scr"+"ipt type='text/javascript' defer='defer'>"+script+"</script" + ">"; 
	} 

var box = new SimpleDialog("hersh"+Math.random(), true); 
	parent.box = box; 
	box.setTitle("Special Care Notice"); 
	box.createDialog(); 
	box.setWidth(350); 
	box.setContentInnerHTML("<p align='center'><img src='https://c.cs21.content.force.com/servlet/servlet.ImageServer?id=015q0000000BNcN&oid=00Dq0000000CSTt&lastMod=1519241870000' style='margin:0 5px;'/></p><p align='center'>Please note: {!Contact.Special_Care_Comments__c}</p><p align='center'><br /><button class='btn' onclick='window.parent.box.hide(); return false;'>Okay</button></p>"); 
	box.setupDefaultButtons(); 
	box.show(); 
} 

script = "Special Care Comments: specialcare;"; 

insertScript(script);

Now I would like to create a similar pop-up with two buttons. The second button, I would like it to open a new window (visualforce page). I just can't get it to work! Instead of the 'window.parent.box.hide();' onclick function, I've tried 'window.open('/apex/nameofpage');' as well as tried a specific url, but whenever I go to click the button then, absolutely nothing happens.

Can someone help?
Naomi HarmonNaomi Harmon
Nevermind! I answered my own question. By declaring the url in a variable outside the function and then calling it within window.open(), I was able to get it to work. :)
Waqar Hussain SFWaqar Hussain SF
Great :)