Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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.

share|improve this question
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 '13 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 '13 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 '13 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? –  Jim Minichiello Jun 17 '13 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 '13 at 0:06

1 Answer 1

up vote 5 down vote accepted

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"/>

share|improve this answer
    
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 '13 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 '13 at 3:17
    
This doesn't seem to work anymore, salesforce blocks the script from reaching the other domain. –  DashboardReport 2 days ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.