What the page can contain ?
In broad sense, visualforce page contains visualforce tags & optionally html, css & javascript. Most developers expect it to contain that standard HTML page contains.Can it contain other than HTML contents ?
yes. visualforce is not designed to be just the HTML content. It could be following,- Javascript
- CSS
- CSV
- MS Word
It could be any type that W3 standard supports.
How to achieve that ?
we need to pass the content type attribute to the page tag. Then, it will expect the content to be in that format.
Where is the code ?
For illustration, i have given the page for csv file & javascript. When you load this page, these pages will get downloaded, because, it's not a html page & cannot be loaded.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page contentType="text/csv#MyReportData.csv"> | |
Id, Name, Date, IsClosed | |
0a123432434, TestOpp, 12/12/2016, true | |
</apex:page> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page contentType="text/javascript#MyScript.js"> | |
function globalFunction() { | |
alert('Hi, im global function'); | |
} | |
</apex:page> |
No comments:
Post a Comment
Thanks for reading my blog !