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
hemmhemm 

open new window in remoteAction response

For the life of me, I cannot get this to work.

 

I have a remoteAction method returning a URL String. I am then trying to use window.open to open that URL.  For some reason, the browser will not launch a new window and open that URL.  I am certain my code is hitting that line.  Below is a generic example of what I am trying to do.

 

mynamespace.mycontroller.getMyURL(inputString, function(result, event){ 
        	if (event.status) {
        		window.open (result);
       	       	}
       	       	, {escape:true});

 

Best Answer chosen by Admin (Salesforce Developers) 
hemmhemm

I wanted to do a new window and did get it to work. The key was first running a console.log(this); command to  let me understand the scope of the script. It was a DOM Window that was actually output when I did this.  I got my code working by using this.open(...); instead of window.open.

 

mynamespace.mycontroller.getMyURL(inputString, function(result, event){ 
        if (event.status) {
        	this.open (result);
       	}
}, {escape:true});

 

All Answers

Rahul SharmaRahul Sharma

Hi hemm,

try to alert and check whether returned url is proper or not.

hemmhemm

Yes, it's a good URL. I've even tried to just open google.com. No dice. Can you run code that actually works? Please test it to make sure it actually launches a URL in a new window/tab.

Rahul SharmaRahul Sharma

Hi hemm,

It works fine if we use self.parent.location instead window.open.

seems that there's some issue with it.

hemmhemm

I wanted to do a new window and did get it to work. The key was first running a console.log(this); command to  let me understand the scope of the script. It was a DOM Window that was actually output when I did this.  I got my code working by using this.open(...); instead of window.open.

 

mynamespace.mycontroller.getMyURL(inputString, function(result, event){ 
        if (event.status) {
        	this.open (result);
       	}
}, {escape:true});

 

This was selected as the best answer
Rahul SharmaRahul Sharma

ohh, good to know the solution. :)

SK R.ax1448SK R.ax1448

Hi,

I am facing similar problem, could you please share the full code (VF page & Controller).

 

 

 

Thanks in advance.