InfoPath 2010 close the browser window
Friday, June 17, 2011 at 4:39PM How do you close the browser window (or tab) completely when you close an InfoPath browser form?
Quick steps:
- In your URL to open your form, specify the source parameter. This is the URL InfoPath will return the user to after the browser form is closed.
- Create a simple SharePoint web page with a bit of JavaScript to close itself.
- Set the source parameter to this page.
1. Use the Source
MSDN documentation: http://msdn.microsoft.com/en-us/library/ms772417.aspx
When you close a browser form, either via the Close ribbon button, or via the Close action in rules, when the source parameter isn't specified, you end up on this page:
Figure: Silly and really redundant.
If you specify a source parameter, when the user closes the form the browser will redirect to that URL. This could be the homepage of your site.
With Form Server you can use a few special values such as ~sitecollection or ~site
2. Create a web page that closes itself.
Create a page (wikipage or publishing page), and add this JavaScript magic here.
<script language="javascript" type="text/javascript">
window.open("", "_self");
window.close();
</script>
Why is this javascript so strange? The reason is that if you just call window.close() directly, most browsers will check if the current window was opened from a parent window (such as a popup), and will throw an offensive prompt to the user.
Figure: JavaScript close window confirmation - we don't want this
There are a few different ways to trick the browser, the one that I use above basically tells the browser window to open itself, so now the browser thinks it's got a parent (which is itself), and now won't prompt the user for close confirmation.
3. Set the URL parameter
So now when you close your browser form, it will redirect to our close.aspx page, which will actually close the web browser window (or tab).






Reader Comments (13)
Awesome.. thanks.. you saved my day
Great tip! Appreciate you sharing.
I was able to use this on a Sharepoint List New Item link I am opening in a new browser window. I wanted the window to close after clicking Ok to save the new item vs going back to the List itself upon completing. Now we are able to feed the List data without uncessary page clicks/views to the List itself afterwards
thanks heaps. worked like a charm!
Could you provide a sample of the the code with the source - I cannot get this to work.
Using a custom web part page with a SharePoint list. this does not work. Form window stays open
apparantly I can't put code in here as I was going to show you my string
Hi Amy,
When your InfoPath form closes, is it redirecting to the page that you've created?
If it is, then check your close page - your javascript might be incorrect, so it's not self-closing.
Excellent!!
Even with my very limited javascripting knowledge i managed to pull this off.
I created an .aspx page with only the javascript mentioned above. Within my sitecollection i uploaded this .aspx page as a "Site content type". Next up was using the URL of this site content type as the source location of my web form: http://ictformulieren.d1.zg/_cts/Close/close.aspx
Now, on closing or submitting the form it perfectly closes the browser window or tab.
Can't believe i got this to work... :-D
Thanks a million!!
Awesome! Thank you for the tip as well.
Brilliant - THANKS!
In my case, It's not working...
function showAddFeedbackDialog()
{
var options = {
title: "Test",
allowMaximize: false,
autoSize:false,
width: 1200,
height: 750,
url: "http://server/site/_layouts/FormServer.aspx?XsnLocation=~sitecollection/FormServerTemplates/Form.xsn&SaveLocation=~sitecollection/Library/Forms&Source=~sitecollection/SitePages/Close.aspx&OpenIn=Browser"
};
SP.UI.ModalDialog.showModalDialog(options);
But it redirects me always to "The form has been closed"
Hi, my process is built using K2 blackpearl. I integrate InfoPath to SharePoint and I want the same thing as you are talking above. I want to redirect to a sharepoint calendar list. I do not know where to set the url parameter.
Kindly show me the place where I can go to set the url parameter for the source.
Thank in advance.
Hi Wandath,
If you set the Source parameter to your calendar list that should work.
Hi Mario,
I find that with new forms (XsnLocation), you don't need the Source parameter. The XSN closes by itself. I've only used the Source=~close.aspx trick when I'm using XmlLocation parameter for existing forms.
Hi JohnLiu.NET,
The thing is that I do not know where to set the Source parameter. On InfoPath? Where? I really have no idea.
Thanks.