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.
sataratrogdorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

yogi4lifeCommented:
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.
0
michaelcristCommented:
Use an Excel Web Access Web Part rather and load the sheet into it rather than opening the sheet directly from the Document Library.
0
sataratrogdorAuthor Commented:
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.
0
Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

sataratrogdorAuthor Commented:
by ajax, of course I mean javascript.
0
yogi4lifeCommented:
1. Add a "Content Editor Web Part" to the appropriate page.
2. Edit the Web Part and click "Source Editor"
3. Make code similar to the following:

<script type="text/javascript">
_spBodyOnLoadFunctionNames.push("fixLinks");
function fixLinks() {
  alert('trying to fix links');
  var e = document.getElementById('group').getElementsByTagName('a');
  alert( e.length + " links found" );
  for (var i=0; i

4. Set the Content Editor Web Part to hidden

Thats really all there is to it...
Of course my code is very simplistic and you will have to modify to make it robust and appropriate for your SharePoint installation. The call to _spBodyOnLoadFunctionNames.push("....") is necessary to postpone any processing until the page has been loaded and the DOM is available for manipulation. This is a built in SharePoint function which pushes your function onto an ONLOAD stack of functions that will be processed when the page is ready/loaded completely...
0
sataratrogdorAuthor Commented:
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.
0
yogi4lifeCommented:
One way to solve your problem would be to make a function that waits for the loading of the Web Part to happen.

setTimeout('checkForWebPartReady()', 1000);

in this JavaScript function checkForWebPartReady you will have to do a:

document.getElementById('') and see if that exist and if it is
the webpart has loaded....

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sataratrogdorAuthor Commented:
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?
0
yogi4lifeCommented:
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...
0
sataratrogdorAuthor Commented:
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!
0
sataratrogdorAuthor Commented:
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.
0
MARKNOVACommented:
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
0
sataratrogdorAuthor Commented:
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
0
MARKNOVACommented:
I knew it would be right in front of me!! Thanks heaps sataratrogdor. You're a legend!
0
BrianCowleyCommented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SharePoint

From novice to tech pro — start learning today.