1

I have a visualforce tab that is a renderAs = PDF. Is there a way to do a target = _blank on a tab? It currently overwrites the page you are on and downloads the PDF. I want it to target a new window or browser tab, and download from there. There is no button or link to generate the pdf. It is just the tab. As far as I can tell it is not possible to do a target blank on a visualforce tab.

I was thinking about JS window.open once the document was ready but because it is a PDF there is no content loading until after the PDF has been downloaded.

Any insight would be appreciated!!

Some Code I have tried:

<script type="text/javascript">
$(document).ready(function() {
    console.log('I got in to the function');
    window.Open('/servlet/servlet.Integration?lid=01r4C012340L1vG&ic=1&linkToken=Vm546548722veU1qb');
});
</script>

or

<apex:page controller="phoneListController" renderAs="pdf" showHeader="false" applyBodyTag="false" target="_blank">

or

function newTab() {
    console.log('I got into JS');
    alert('ok');window.Open('/servlet/servlet.Integration?lid=01r4C123450L1vG&ic=1&linkToken=VmpFPSxNakyTWXNQLFlXWmtNRo');
}
window.onload = newTab;
console.log('got in');

Full VFP:

<apex:page controller="testController" renderAs="pdf" showHeader="false" applyBodyTag="false">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>

@page {
    @bottom-right {
        content: "Page " counter(page) " of " counter(pages);

        font-size: 8px;
    }
}
</style>
<script type="text/javascript">
function codeAddress() {
    console.log('I got into JS');
    alert('ok');window.Open('/servlet/servlet.Integration?lid=01r4C000000L1vG&ic=1&linkToken=VmpFPSxNakF4Tnkwd01TMHlOMVF4T0RveU1qb3pOaTQyTkRaYSw3WnBqWHNfTFd2bDFfTTJDSk9XWXNQLFlXWmtNR0po');
}
window.onload = codeAddress;
console.log('got in');
</script>

</head>
<div class="container">
    <h2>Title</h2>
    <br/>
    <div>
        <table>
            <tbody>
            <thead>
            <tr>
                <th>data</th>
                <th>data</th>
            </tr>
            </thead>
            <apex:repeat value="{!allPeople}" var="depts">
            <tr>
                <td style="{!IF(person.Leadership__c == true, 'background-color: #efefef', '')}">{!person.Name}</td>
                <td style="{!IF(person.Leadership__c == true, 'background-color: #efefef', '')}">{!person.Phone}</td>
            </tr>
            </apex:repeat>
            </tbody>
        </table>
    </div>
</div>
</apex:page>
4
  • 1
    Olivia. can you show us some of the code you tried? Commented Jan 24, 2017 at 18:46
  • @SebastianKessel I update my question with some code I have tried. It is not reading the javascript at all. So I am curious if there is a way around it, perhaps by doing a visualforce function?
    – Olivia
    Commented Jan 24, 2017 at 19:11
  • We need a bit more context. Where is this JS located? How are you trying to open it? I think we can help you here. Commented Jan 24, 2017 at 19:18
  • @SebastianKessel I apologize. I updated again with the full visualforce page. The allPeople is a list from the controller. I have a javascript at the top of the page in the <head> tags.
    – Olivia
    Commented Jan 24, 2017 at 19:31

1 Answer 1

2

The issue is that you're trying to open the PDF from within itself. That doesn't quite work.

There are several ways to approach this. The easiest one is to create a new page and make sure the tab points to it. Then, from this new page, open your PDF. A simple example below. (I will mock up with JS, you can actually mock this with Apex if you prefer)

newPage.page

<apex:page >

<script type="text/javascript">
function codeAddress() {
   window.open('/apex/*myPage*', '_blank');
}
window.onload = codeAddress;

</script>

This content appears after the PDF has been loaded, you could do a redirect someplace else if you prefer.

</apex:page>

You must log in to answer this question.

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