Link to home
Start Free TrialLog in
Avatar of sataratrogdor
sataratrogdor

asked on

Excel Services hyperlink redirect to same Window

Experts,

I am using Excel Services to show data to my users.  I have a hyperlink set up on the excel file which links to a document library, with a filter (by passing a parameter in the URL).

(Filter for all documents where "Objective" = "Stars")

Like This:
http://<<MyWebsite>>/Documents/Forms/AllItems.aspx?View=%7bAA161797-7849-4ACB-B4A1-75AC55B9ACF7%7d&FilterField1=Objective&FilterValue1=Stars

The default behavior for excel services is to open any links that point outside of the workbook in a new window.  

I would rather have the document library on the same page that the excel services web part is, and simply refresh that page (rather than open a new browser).

I can play with the URL in the same way, on that page
http://<<MyWebsite>>/PageWithExcelServicesLinkANDDocumentLibrary.aspx?View={8C011E15-CE3F-4494-9D74-2962C18D8483}&FilterField1=Objective&FilterValue1=Stars

Which would work perfectly, were I able to redirect the hyperlink to the same window.

Any Ideas on how I can change that default behavior?

Thanks.
Avatar of yogi4life
yogi4life
Flag of Norway image

The way a hyperlink tag ( like:  xyz ) works is that the link is opened in the same window. But with Excel Services the HTML generated has a target="_blank" attribute added.

Are you able to change that attribute to _self ?

If not - there is work-arounds since you could attach a JavaScript to your page which replace the target="_blank" to target="_self" - that should do the trick.
Use an Excel Web Access Web Part rather and load the sheet into it rather than opening the sheet directly from the Document Library.
Avatar of sataratrogdor
sataratrogdor

ASKER

I am using the Excel Web Access web part.  My page is configured with 2 webparts, the document library, and the excel webpart.  The link in excel points back to the same page, and applies a filter to the document library.

I like the Ajax idea, but haven't had a chance to google it.  yogi4life, do you by chance have a link to an example, or can you provide me with a starting point?

Thanks.
by ajax, of course I mean javascript.
SOLUTION
Avatar of yogi4life
yogi4life
Flag of Norway image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is a good start, but does not get me out of the woods.

On closer inspection, the Excel web part appears to be inserting its HTML after the script is run.

I have observed that if I view source on the full page, I can see the placeholder for the excel web part, but don't see the actual HTML rendered by it.

If I view source by clicking on the actual excel portion of the page, I get the HTML that the web part renders (that has the links with the default _blank, instead of _self).

If I can get the script to fire on the HTML that the excel web part generates, I will be all set.  I am not sure how I can sneak this script into that section of the document.

Appreciate your thoughts.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I am still working on the script that will work for me.  The problem that I am having is that the HTML for the excel web part is not loading on the same page that the content web part is.  In other words, as I described above, if I select "view source" on the page when it is fully loaded, I do NOT see the HTML for my excel spreadsheet.  However, if I right click-->view source on the excel sheet, I see the HTML only for that portion of the page.  How can I access that HTML using the script?
If you do a view source... you might not see the dynamically generated part of the DOM... So it might be accessible from Javascript anyhow. Which version of Internet Explorer are you using?

IE 8 has a very good "Developer Tools" menu choice on the TOOLS drop-down menu - also accessible with F12...
Chimminy Chunga.  Thanks for the simple pointer for F12.  That is indeed a powerful tool.  nice to know it exists.

I am now closer than ever to having this thing solved.  I have it behaving in exactly the way that I would like it to, by using the following script:

<script type="text/javascript">
_spBodyOnLoadFunctionNames.push("fixLinks");
function fixLinks() {
  setTimeout('runAfterDelay()',1000);
}

function runAfterDelay(){

   var e = document.frames["ctl00_m_g_39d9519a_cccb_4f29_92a6_fc6853f82445_ECSFrame"].document.getElementsByTagName('a');

  for (var i=0; i < e.length; i++ ) {
     e[i].setAttribute('target','_parent')
  }
}
</script>

Because the Excel Web part implements this as an iframe, this is the only way that I found to access the iframe page.  What I dislike about this code, is that I am forced to go find the ugly name for the iframe control.

For now, I am happy about this solution!

Thanks!
I appreciate that yogi4life didn't solve it completely, but made me do a bit of digging on my own.  It helped me solve it more completely.
Hi all - thanks heaps for this. It's been a godsend. I do have one question though. I've been playing around with this code on and off for days and keep getting stumped by the following line:
var e = document.frames["ctl00_m_g_39d9519a_cccb_4f29_92a6_fc6853f82445_ECSFrame"].document.getElementsByTagName('a');

What's the easiest way of finding the frame ID of my Excel Web services part (ie the ctl00_m_g_39d9519a_cccb_4f29_92a6_fc6853f82445_ECSFrame) part? I've searched and searched and either come up with null values or simply can't find it.

Any help would be HUGELY appreciated!!

M
Make sure you are using IE.  (This script doesn't work for me in FireFox).

Once your page loads, and you can see the excel spreadsheet that has the links on them, press F12.  Then use the search feature, to find some text that is only in your excel page.  You should then be able to scroll up to where the <iframe> tag begins, and note the ID that it has been assigned.


iframe.png
I knew it would be right in front of me!! Thanks heaps sataratrogdor. You're a legend!
Hi guys, I am having the same problem with Excel services and I have tried the solution above to no avail.  When I click on the link it is still opening in a new window.  I am using SP2010 and the workbook was created in Office 2010.  Does this make a difference?

Thanks

Brian