How to embed Web Page in an InfoPath Form

Purpose

This document will give you an in-depth idea on how to embed a web page within an InfoPath form. The web page can be invoked with different URLs on click of a button.

The proposed solution below will help us avoid using Activex controls to act as custom controls within an InfoPath form. This will also avoid the problems of having a webBrowser control within an internet browser page. (see MS KB http://support.microsoft.com/kb/q237685/)

It is nearly impossible to add an iframe to the Xdocument.DOM of InfoPath

Sample Scenario

An Application form has to get details from a given URL in the InfoPath page. User will click on the URL and the webpage will be populated within the InfoPath form, so that the User doesn’t have to navigate out or switch to a different browser window.

Solution

A new TaskPane will be created and associated with the InfoPath form. This TaskPane by default will take a simple user created html page. On click of the button to the right of the given URL, TaskPane will be navigated to that specific URL. This is done by invoking an onclick event which navigates the TaskPane to the given URL.

Step by step walk-through

  1. Open a notepad and paste the following:
    <HTML>
    <body>
    Clickon the Go button against the URL to open the web page
    </body>
    </HTML>
  2. Save and close the notepad file as myTaskPane.HTML
  3. Open a new form in the Design Mode in InfoPath
  4. Go to Menu/Tools/Form options/Advanced
  5. Check “Enable Custom Task Pane”
  6. Type Task Pane name as “WebPagePane”
  7. Click on the Resource Files and addmyTaskPane.HTML from its location.
  8. Select Task Pane location as myTaskPane.HTML from the Form Option window.
  9. Click Ok to close the Form Options window.
  10. Add the text box named “URL” to the form
  11. Add a button on the right of the URL textbox with a name/ID “btnGo’; label the button as “GO”
  12. Double-click on the GO button
  13. Click “Edit Form Code” button
  14. A script editor will be opened; paste the below code in the editor, save and close.
    functionbtnGo::OnClick(eventObj)
    {
    var objTaskPane;
    var objXMLNode;
    objXMLNode =XDocument.DOM.selectSingleNode("/mySample/URL");
    if (objXMLNode.text != ""&& objXMLNode.text != null)
    {
    // Set a reference to the custom task pane.
    objTaskPane = XDocument.View.Window.TaskPanes(0);
    objTaskPane.Navigate(objXMLNode.text);
    }
    }
  15. Click on the Preview Form, type a URL and click GO... works!!
  16. Close the preview and save the form.

 

Note: If you would like to publish this form to public, you need to remove the security restrictions.

  • Go to Menu/Tool/FormsOptions/Security
  • Uncheck “automatically determine security..”
  • Check Full Trust option
  • Check ‘Sign this form” and create or use a certificate.

Install this certificate in the client computer where you use this form.

Conclusion

This is a simple solution for having a web page within an InfoPath form. Task Pane can be moved to any corner of the InfoPath window as per user’s convenience. Security Levels of the forms has to be decided as per the requirements.

Download Sample