Using the button control to launch a web page - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Using the button control to launch a web page

Last post 11-03-2011 09:30 PM by RoseMary. 12 replies.
Page 1 of 1 (13 items)
Sort Posts: Previous Next
  • 11-14-2008 02:05 PM

    Using the button control to launch a web page

    I need to launch a web page from within an InfoPath form. I could use the Hyperlink control in InfoPath, but I have a need to launch it using the button control. In looking at the options for the button control, the only way to do this, if at all, is to use the Action, Rules and Custom Code, and plug in the hyperlink to the web page I want to launch in the Edit Form Code... section.

    I'm don't know JS, so I'm hoping that if this is possible someone would provide a sample code that I can include in the Edit Form Code... section. Many thanks in advance for your help.

    G

  • 11-14-2008 06:49 PM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: Using the button control to launch a web page

    Hello Welcome to the Forum,

    You can open using the below code to open the form,

    Application.XDocuments.Open(<Url of the form>);

    If you set any hyperlink to one field then get the value and pass that value to open the form.

  • 11-17-2008 06:59 AM In reply to

    Re: Using the button control to launch a web page

    Thanks, Shiva. I tried your suggestion, but got an "InfoPath cannot open the selected form." Let me just clarify what I'm doing. I have an InfoPath form named Project Status. In this form I've added a button control in the form named View Financial Data. Theoretically, when someone presses this button, an html page (http://nummdp01/Sites/BusinessPortal/Financial%20Summary.htm) opens up in a separate window. This is because the Project Status form contains status information for the given project, but the financial information is found in a separate place (webpage).

    So, based on the information you provided, I double-clicked on the button in the form to open it for edit and then clicked on the Edit Form Code... In Microsoft Script Editor, the following information was present (I've excluded the non-essential comments)...then plugged in the URL I need to launch in the 'function CTRL84_8::OnClick(eventObj)'. I presume this is the function that handles the depressing of the button.

    //general comments...

    XDocument.DOM.SetProperty ("SelectionNamespaces", 'xmlns:x....")

    //</namespacesDefinition>

    //general comments...

    function XDocument::OnLoad(eventObj)

    {

        // Write your code here

    }

    //more comments

    function CTRL84_8::OnClick(eventObj)

    {

         //Write your code here

    Application.XDocuments.Open(<http://nummdp01/Sites/BusinessPortal/Financial%20Summary.htm>)

    }

    What am I doing wrong? Again thanks for help.

  • 11-17-2008 07:14 AM In reply to

    • Anuma
    • Top 25 Contributor
      Female
    • Joined on 07-20-2005
    • India
    • Posts 525

    Re: Using the button control to launch a web page

    Hi, 

    Try this:

    this.Application.XmlForms.Open(templatefilename);  

    Application.Xdocuments doesn't exist in forms with the 2007 object model.

    Anuma Chinthapalli /
    http://www.GGKTech.com
  • 11-17-2008 08:25 AM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: Using the button control to launch a web page

    Hello,

    Before passing the complete URL to below the code as Anuma given above to you and check once that url is opened in IE page.

    this.Application.XmlForms.Open("URL of the Form");

  • 11-18-2008 11:58 AM In reply to

    Re: Using the button control to launch a web page

    Hi, Shiva! Thanks so much for your help and patience. I should clarify that we're using InfoPath 2003. So, I plugged in the code as follows in Microsoft Script Editor for this button control in the InfoPath form...

    function CTRL84_8::OnClick(eventObj)

    {

        //Write your code here

        this.Application.XmlForms.Open("http://nummdp01/sites/BusinessPortal/Lists/Business%20Portal%20Feedback/AllItems.aspx");

    In InfoPath Preview mode, I received the following error message when I pressed the button...

    "A run-time error has occurred.

    Do you want to debug?

    The following error occurred:

    'this.Application.XmlForms' is null or not an object

    File:script.js

    Line:37"

  • 11-23-2008 11:10 PM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: Using the button control to launch a web page

    Hello,

    The above code is in C#. After you debug and your error on script.js? Are you using same code in jscript file?

    If you want to open the form using jscript code then use below the code,

    window.external.ExecuteFile("http://nummdp01/sites/BusinessPortal/Lists/Business%20Portal%20Feedback/AllItems.aspx");

    Note: Make sure that the above URL of the form it will open in Internet Explorer without giving any error message.

  • 02-10-2009 10:39 AM In reply to

    Re: Using the button control to launch a web page

    Did anybody get this working?

     I've tried the code above as follows:

     

    function CTRL2_17::OnClick(eventObj)

    {

    window.external.ExecuteFile("URLofthesite");

    }

     The form will load but clicking on this button returns the error that 'window' is undefined

     

  • 02-11-2009 10:56 AM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: Using the button control to launch a web page

  • 02-20-2009 08:39 PM In reply to

    Re: Using the button control to launch a web page

    I checked out the link...what does this mean exactly?  I am not sure I understand...could you just provide us an example of the syntax that would work?  I to get the "window is undefined" error and after reading the link you referenced I am not sure I comprehend the relevance, can you please clarify?

  • 02-24-2009 09:23 PM In reply to

    Re: Using the button control to launch a web page

    This code here will launch a new internet explorer window to the URL you specify.  It's an Activex control so you'll need to have that allowed or prompt you to allow it to run in the browser

     function CTRL2_17::OnClick(eventObj)

    {

     var sh=new ActiveXObject("Wscript.Shell");

    sh.Run("iexplore.exe"+" "+http://yoursite.here);

    }

     thanks Shiva for your input.  I think this is what we're looking for here.

  • 09-21-2011 06:45 PM In reply to

    Re: Using the button control to launch a web page

    This code doesn't work.  When my form loads I get "InfoPath cannot open the selected form" error.  Any other suggestions? 

  • 11-03-2011 09:30 PM In reply to

    Re: Using the button control to launch a web page

    Hi, 

    I am using Infopath 2007 and it is not browser enabled.

    My requirement is to open a web page like http://www.google.com on the button click and it should also close the existing form(i know closing form can be achieved using rules). Please help for redirection

    I tried the suggestion which was provided

    this.Application.XmlForms.Open("http://www.google.com");

     but i got the below error.

    /Error - Start 

    System.Runtime.InteropServices.COMException
    InfoPath cannot open the following file: http://www.google.com.
    The form is attempting to redirect itself to a different and potentially unsafe location.

    The form is accessed through a redirection from different domain, which is not allowed. If you want to open this form, copy it to a location within your security domain.
    Access is denied.

    /Error - End

Page 1 of 1 (13 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.