Click here to Skip to main content
Click here to Skip to main content

How To Embed a Web Page in an InfoPath Form

, 5 Oct 2006
Rate this:
Please Sign up or sign in to vote.
How to embed a 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 this article).

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. The user will click on the URL and the Web page 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 Notepad and paste the following:

    <HTML>
        <body>
            Click on 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 add myTaskPane.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 textbox 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.

    function btnGo::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/Forms Options/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 have to be decided as per the requirements.

Contact

For any further information or any queries, reach out to me at firozozman@hotmail.com

My blog: www.firozozman.com.

History

  • 5th October, 2006: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

FirozOzman
Web Developer
Canada Canada
Firoz Mohammed (Firoz`Ozman) |
MCSD.Net, MCTS (BizTalk 2004 & 2006)
Avanade Inc: www.avanade.com |
Toronto, Canada |

Comments and Discussions

 
QuestionHow to embed an infopath in a webpage Pinmembermanasa162329-Nov-07 3:33 
GeneralDownload? [modified] PinmemberOskar Austegard9-Oct-06 10:53 
I'm lazy - I want to see a demo with minimal investment. So an InfoPath file download would be nice to have.;)
 
And the following returns null when I test:
objXMLNode = XDocument.DOM.selectSingleNode("/mySample/URL");

 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140814.1 | Last Updated 5 Oct 2006
Article Copyright 2006 by FirozOzman
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid