0

I have written a script to open a page in new tab on click of a command button. Unfortunately I get the following error:

window.open is not a function()

I have not created any variable named "Open" which may have over written the open() function.

My script is like this

<script>  
function newpagePDF() {
          alert('Hi11');
          var stringcase = '{!caseid }';
          var newpage = window.Open('/apex/ZEB_RMA_Pdf?CaseId='+stringcase );
    }

</script>

My command buton is :

<apex:commandButton value="Generate Pdf"   onclick="newpagePDF();"/>
2
  • What browser are you using ? Jun 23, 2015 at 6:56
  • I am using google chroome Jun 23, 2015 at 6:59

5 Answers 5

1

Try following statements:

window.open(('/apex/ZEB_RMA_Pdf?CaseId='+stringcase), window.name, "height=600,width=700");

or

window.open(('/apex/ZEB_RMA_Pdf?CaseId='+stringcase), '_blank', "height=600,width=700");
8
  • Sorry ..but its not working Jun 23, 2015 at 6:53
  • Are you getting exception or the tab is opening in new tab? Try to copy and paste the given code and make sure stringcase is defined. It should work. @AnkitaSingh You have typo mistake in function.
    – Ashwani
    Jun 23, 2015 at 6:56
  • I have defined string case.I am getting a new error now : GET na10.salesforce.com/17181/logo180.png 404 (Not Found) Jun 23, 2015 at 7:00
  • This error has no relation with the JavaScript you wrote. I may ignore it @AnkitaSingh.
    – Ashwani
    Jun 23, 2015 at 7:02
  • 1
    Try it window.open(('/apex/ZEB_RMA_Pdf?CaseId='+stringcase), '_blank', "height=600,width=700"); @AnkitaSingh
    – Ashwani
    Jun 23, 2015 at 7:06
2

The reason actually is pretty simple: Unlike apex, javascript is case-sensitive. So instead of using window.Open, use window.open will resolve your issue

5
  • i am already using window.open in my code..still it doesnot work Jun 23, 2015 at 6:54
  • @AnkitaSingh what is the error then? Shouldn't be Open is not a function though
    – Lance Shi
    Jun 23, 2015 at 6:56
  • Error is : GET na10.salesforce.com/17181/logo180.png 404 (Not Found) Jun 23, 2015 at 6:59
  • @AnkitaSingh , this is the error in your visualforce page. Though you have defined your string and the caseId is correct, when it passes to VF page and try to get the resource, it failed to get the logo. I guess this is a very separate question. If you still need guidance on that, I would suggest you paste your VF code in.
    – Lance Shi
    Jun 23, 2015 at 7:03
  • Kindly refer to link for code Jun 23, 2015 at 7:22
0

Change the window.open as below,

var newpage = window.Open('/apex/ZEB_RMA_Pdf?CaseId='+stringcase ,'_blank');

_blank - opens page in new tab

Try this.It will work..

6
  • Its still not working Jun 23, 2015 at 6:34
  • whether it is opening in same page? Do you have code that page*(ZEB_RMA_Pdf)? Jun 23, 2015 at 6:35
  • it is opening in same page. i didnt get your second question..sorry? Jun 23, 2015 at 6:37
  • I tried opening a different page..that also does not work..that also gives me the same error Jun 23, 2015 at 6:38
  • Sorry my question had typo.Do you have a page like ZEB_RMA_Pdf?.Also change that Open to open in script Jun 23, 2015 at 6:39
-1

you can try this code on the vf page

<apex:commandButton value="Generate Pdf" action="{!----}" reRender="" onclick="window.open('/apex/ZEB_RMA_Pdf?id={!Case.Id}');" />

in the place of action u write the mehthod name whom u want to open in the new page

1
  • <apex:commandButton value="Generate Pdf" action="{!----}" reRender="" onclick="window.open('/apex/ZEB_RMA_Pdf?id={!Case.Id}');" /> Jun 23, 2015 at 7:22
-1

you can try this code on the vf page :

<apex:commandButton value="Generate Pdf" 
                        action="{!----}" 
                        reRender="" 
                        onclick="window.open('/apex/ZEB_RMA_Pdf?id={!Case.Id}');"     
    />
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .