12

I'm embedding a dashboard in a visualforce page using an iframe:

<iframe src="/01ZJ00000007JGa?isdtp=vw"/>

When I try to click on any component to load the underlying report, I get this javascript error:

Uncaught TypeError: Cannot read property 'Listener' of undefined   iframeinterface.js:1
Sfdc.xdomain.IframeInterface.handleOnload                          iframeinterface.js:1
window.onload                                                      crossDomainProxy.html:6

The affected file is served from <SFHOST>/xdomain/iframeinterface.js and the specific line that's causing the error is:

("sfdc-console" === b ? top : 
    "undefined" !== typeof a.targetParentFrame ? 
         parent.frames[a.targetParentFrame].frames[b] : 
             parent.frames[b]
).Sfdc.xdomain.Listener.accept(a)

Any thoughts about what's going wrong and how I can fix it?

UPDATE

I was able to accomplish what I need to with the following hack described in this answer, made possible by the fact that I'm on the same domain. But I'll leave the question open, looking for a more thorough explanation and non-hackish way to embed a dashboard in Visualforce.

5
  • 1
    Is the purpose of isdtp just to strip off the headers and footers of the dash and just expose the dashboard? I tried with lt and mn params it seems to work, with vw (ca-peterson.com/2011/11/magic-isdtp-param.html)I get the same domain error Uncaught TypeError: Cannot read property 'xdomain' of undefined
    – Rao
    Feb 21, 2013 at 19:12
  • Interesting... And yes, I'm using isdtp to hide headers since this is embedded. Confirmed that links work with mn (although it's ugly)
    – Benj
    Feb 21, 2013 at 19:20
  • 1
    Update: seems like the problem happens in the srcUp method. It only happens when clicking on chart images, not on table components
    – Benj
    Feb 21, 2013 at 19:35
  • Why bother building a Visual Force page when you can just use this code directly in an HTML Area Home Page component? < iframe src="/000000000000000?isdtp=vw" frameborder="0" height="768" width="1024"></iframe> The 000000000000000 is your Dashboard page ID. It displays the Dashboard seamlessly. But, I face the same problem you're all talking about, which is that the links don't work. Is there an HTML solution rather than Apex?
    – user3062
    Jun 17, 2013 at 20:03
  • @Jim, because I don't want it on my homepage - I want it embedded in another page. But yes, the solution accepted as an answer below uses Javascript (not Apex) to solve the broken links issue.
    – Benj
    Jun 18, 2013 at 0:06

3 Answers 3

4

Loading the Dashboard with isdtp removes the header and sidebar, but isn't officially supported. When you do this, SFDC replaces all the links with a call to the srcUp() function, which doesn't work in this context.

To get around that, add the following script to your VF page to change the links back:

<apex:page>

<script>
jQuery( function ($) {

     $('#iframeID').load( function() {              
         var $frameDoc = this.contentWindow.document,
             urlMatch = /srcUp\(%27(.*)%27\)/;

         $('a[href*="srcUp"]', $frameDoc).each( function () {
             this.href = decodeURIComponent(this.href.match(urlMatch)[1]);
         });
     });

});
</script>

<!-- the rest of your page goes here -->

<iframe id="iframeID" src="/01ZJ00000007JGa?isdtp=vw"/>

3
  • I tried the code mentioned above but I got this error in the console "Uncaught ReferenceError: jQuery is not defined". am I missing something? <apex:page> <script> jQuery( function ($) { $('#iframeID').load( function() { var $frameDoc = this.contentWindow.document, urlMatch = /srcUp\(%27(.*)%27\)/; $('a[href*="srcUp"]', $frameDoc).each( function () { this.href = decodeURIComponent(this.href.match(urlMatch)[1]); }); }); }); </script> <!-- the rest of your page goes here --> <iframe id="iframeID" src="/01ZJ00000007JGa?isdtp=vw"/>
    – user2824
    May 10, 2013 at 3:26
  • Yup. You'll need to have jQuery loaded on your page. Easiest way is to add <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> to the top of your visualforce page.
    – Benj
    May 12, 2013 at 3:17
  • 5
    This doesn't seem to work anymore, salesforce blocks the script from reaching the other domain. Oct 28, 2014 at 19:10
0

When I have run across this problem, I ended up re-creating the charts I needed using the analytics:chart tag on a Visualforce page. Not the same as embedding, but it is fully supported. It does mean more maintenance as any changes to the dashboard have to be manually updated. In my particular use case it worked well for them but YMMV.

-3

With Spring 15 release, iFrame is not supported by Salesforce anymore. So we need to have an alternative way to achieve this functionality.

2
  • (1) what do you mean that iframe is no longer supported by Salesforce? This question is about embedding dashboards in Visualforce, and AFAIK there are no limitations on including iframes in a VF page.... (2) This isn't really an answer, so please changing it to a comment on the question or another answer.
    – Benj
    Apr 17, 2015 at 13:42
  • Please refer for link below: success.salesforce.com/issues_view?id=a1p300000008XttAAE Apr 21, 2015 at 12:21

You must log in to answer this question.

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