You need to sign in to do that
Don't have an account?
Problem with opening new window
Hi,
I have created a select screen where the user selects a type of object and then can download a CSV that is created on a different page based on parameters of the object. Everything is working fine except for when I try to use window.open() from this page to open up the page that automatically downloads the CSV.
The error I am getting is:
java.lang.IllegalArgumentException: Illegal view ID window.open(/apex/generatespreadsheet?id=a08i0000000SFrtAAG). The ID must begin with /
If I copy the URL in the window.open to the browser, it works fine.
I'm not quite sure what the problem is about, but I've tried numerous ways to solve it.
Anyone here have any thoughts?
Thanks.
<apex:page controller="DownloadCSV" tabstyle="Function__c" showHeader="false" sidebar="false"> <script> function closeSearchWindow() { window.close(); } function x(){ calldownloader(); } </script> <apex:form > <apex:actionFunction name="calldownloader" action="{!downloader}" rerender=""/> <apex:pageblock title="Data Spreadsheet" mode="edit" id="Everything"> <apex:pageBlockSection columns="1"> <apex:pagemessages /> <apex:inputField value="{!sheet.Scenario__c}" required="true" onChange="x();"/> <apex:commandbutton rerender="Everything" value="rerender" /> <apex:commandbutton action="window.open('{!placetogo}')" value="Create" /> </apex:pageblocksection> </apex:pageblock> </apex:form> </apex:page>
public class DownloadCSV { public Data_SpreadSheet__c sheet{get;set;} public String placetogo{get;set;} Pagereference pref{get;set;} public DownloadCSV(){ sheet=new Data_SpreadSheet__c(); } public void downloader(){ pref = new Pagereference('/apex/generatespreadsheet?id='+sheet.Scenario__c); placetogo='/apex/generatespreadsheet?id='+sheet.Scenario__c; } }
In your apex class, try replacing the following line
placetogo='/apex/generatespreadsheet?id='+sheet.Scenario__c;
with
placetogo = URL.getSalesforceBaseUrl().toExternalForm() + '/apex/generatespreadsheet?id='+sheet.Scenario__c;
p.s. Please leave your feedback (Kudos), if the suggested solution is working.
Hi, I tried your method and here are my results:
When I pull up what placetogo is equal to I get this:
https://c.na15.visual.force.com/apex/generatespreadsheet?id=a08i0000000SFrtAAG
(This is perfect, and what I want the browser to open up in a new window that closes upon running the download)
but when I use <apex:commandbutton action="window.open('{!placetogo}')" value="Create" />
I'm getting this error:
URL No Longer Exists
This is what the address the browser attempted to go to looks like : https://c.na15.visual.force.com/apex/window.open(%27https://c.na15.visual.force.com/apex/generatespreadsheet?id=a08i0000000SFrtAAG%27%29
It seems like I may be using window.open incorrectly or something?
Thanks
You can replace commandbutton with either a commandlink or outputLink tag.
Replace commanbutton with the following line and I hope it will resolve the issue.
<apex:outputLink value="{!placetogo}" style="text-decoration:none;" styleClass="btn" target="_blank">Create</apex:outputLink>
Hi, thanks that worked perfectly!
The way that I've set up the page that gets opened is that it downloads a CSV.
The page opens fine, and the CSV downloads. Is there a way to make the page automatically close once the download starts? Right now, it just stays as an open window with a blank page.
Thanks,
Vivek