Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

The problem:

I want to open an excel document automatically from a custom aspx page in the layouts folder (sharepoint 2010) which refers to a document in a document library. The "DocumentUrl" is replaced automaticly with the correct url and the excel opens. But what's strange is that the page keeps reloading and thus also opening the excel document. Anyone who knows what the problem might be?

The code:

<a id="openExcelCreate" href="<%= DocumentUrl %>" onclick="return DispEx(this,event,'TRUE','FALSE','FALSE','SharePoint.OpenDocuments.3','1','SharePoint.OpenDocuments','','','','1','0','0','0x7fffffffffffffff','','')">Download File</a>
<script type="text/javascript">
  document.getElementById("openExcelCreate").click();
</script>

Updates: I've tried adding "evt.preventDefault();" to the onclick event and the page doesn't reload anymore, but then we have some troubles with saving the excel document... all kind of conflicts (file locked, ...)

share|improve this question
    
Could you please show us the code for DispEx? –  Daniel Ziga Nov 15 '12 at 13:44
    
It's used in core.js from sharepoint, so default code... –  Ruben Herman Nov 15 '12 at 13:45
1  
Try inserting g_varSkipRefreshOnFocus = true; before document.getElementById("openExcelCreate").click(); –  Daniel Ziga Nov 15 '12 at 13:52
    
just saw it also on a website :) I'm trying it now –  Ruben Herman Nov 15 '12 at 13:52
add comment

1 Answer 1

up vote 1 down vote accepted

I've added "g_varSkipRefreshOnFocus = true;" before my onclick event is triggered and seems to work now:

<a id="openExcelCreate" href="<%= DocumentUrl %>" onclick="return DispEx(this,event,'TRUE','FALSE','FALSE','SharePoint.OpenDocuments.3','1','SharePoint.OpenDocuments','','','','1','0','0','0x7fffffffffffffff','','')">Download File</a>
<script type="text/javascript">
  g_varSkipRefreshOnFocus = true;
  document.getElementById("openExcelCreate").click();
</script>
share|improve this answer
add comment

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.