Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

WebBrowser control and JavaScript

Posted on 1999-07-15
6
Medium Priority
?
672 Views
Last Modified: 2012-05-05
Does the VB WebBrowser control support JavaScript?

When I attempt to use JavaScript in the control, I get an error message stating "Object expected".  I suspect it is looking for the JavaScript object.
 
If so, how do I create and reference the JavaScript object?

0
Comment
Question by:vogtster
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1525068
Your problem is something else since it supports java

Press button2
Press button3
Press button1. This page contains some funny javascript.

Private Sub Command1_Click()
    WebBrowser1.Navigate2 "http://www.techinfo.cyco.com/shake.html"
End Sub

Private Sub Command2_Click()
    WebBrowser1.Move 0, 0, 4000, 2000
End Sub

Private Sub Command3_Click()
    WebBrowser1.Navigate2 "http://www.cyco.com"
End Sub

0
 

Author Comment

by:vogtster
ID: 1525069
I have proved JavaScript is running by using a simple page with JavaScript on it and using the "Alert('hi there');" technique.

But calling a function from a clickable image does not work.  This works in a normal website, but not in the browser control.

<a href='#' onClick='openNewWindow('courses.htm')'>
<img height='28' width='97' src=\images\courses2.gif></a>

function openNewWindow(page){
   var leftPosition = (screen.width - 480) / 2;
   var topPosition = (screen.height - 450) /2;
   myWindow = window.open(page,'newWindow','toolbar=0,menubar=0,status=0,location=0,directories=0,scrollbars=1,width=480,height=400,top=' + topPosition + ',left=' + leftPosition);
   myWindow.focus();
   }

0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1525070
Aha popup windows..
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Accepted Solution

by:
Mirkwood earned 100 total points
ID: 1525071


HOWTO: Use the WebBrowser Control NewWindow2 Event
Last reviewed: October 15, 1998
Article ID: Q184876
 


--------------------------------------------------------------------------------

The information in this article applies to:
Internet Client SDK, versions 4.0, 4.01
Microsoft Internet Explorer (Programming), versions 4.0, 4.01


SUMMARY
This article describes how to use the NewWindow2 event, fired by the Microsoft WebBrowser control provided with Microsoft Internet Explorer 4.0, to specify that your browser application should be used in all cases where a new browser window is opened.

This article will describe this procedure using both Visual Basic 5.0 (VB) and the Microsoft Foundation Classes (MFC) that are part of Visual C++ 5.0 (VC).



MORE INFORMATION
The NewWindow2 event occurs when a new window is to be created for displaying a resource. This event precedes the creation of a new window from within the WebBrowser control, for example, in response to a navigation targeted to a new window or to a scripted window.open method.

Event handlers for this event receive two out parameters:

ppDisp: A pointer to the IDispatch interface of a WebBrowser or InternetExplorer object. You set this pointer equal to the IDispatch interface of a new or existing WebBrowser or InternetExplorer object.
Cancel: A pointer to a Boolean value. Setting this value to VARIANT_TRUE causes navigation to stop and no new window is opened.

In order to specify that your browser application should be used when a new window is opened, you set ppDisp equal to a new WebBrowser object that is contained in a new window created by your application. In this scenario, if a user chooses to open a Web page in a new window, the new window in your application will be used to display the new Web page.
Here is some sample Visual Basic code to accomplish this:


   Private Sub WebBrowser1_NewWindow2(ppDisp As Object,
                                      Cancel As Boolean)
      Dim frmWB As Form1
      Set frmWB = New Form1

      Set ppDisp = frmWB.WebBrowser1.Object
      frmWB.Visible = True
   End Sub

Using MFC, you may wish to do this in one of three types of applications:
Dialog-based
Single document interface (SDI)
Multiple document interface (MDI)

Here is some sample MFC code that would accomplish this task in a dialog- based application:

   void CYourDlg::OnNewWindow2(LPDISPATCH FAR* ppDisp, BOOL FAR* Cancel)
   {
      m_dlgNewWB = new CYourDlg;
      m_dlgNewWB->Create(IDD_WBDLG_DIALOG);

      *ppDisp = m_dlgNewWB->m_webBrowser.GetApplication();
   }

Here is some sample MFC code that would accomplish this task in an SDI or MDI application. This code creates a new frame that contains a WebBrowser control. In an SDI application, this frame would appear to the user to look like another instance of the application. In an MDI application, this frame is the same as if the user had chosen to open a new child window.

   void CYourView::OnNewWindow2(LPDISPATCH FAR* ppDisp,
                                BOOL FAR* Cancel)
   {
      // Get a pointer to the application object
      CWinApp* pApp = AfxGetApp();

      // Get the correct document template
      CDocTemplate* pDocTemplate;
      POSITION pos = pApp->GetFirstDocTemplatePosition();
      pDocTemplate = pApp->GetNextDocTemplate(pos);

      ASSERT(pDocTemplate);

      // Create the new frame
      CFrameWnd* pNewFrame = pDocTemplate->CreateNewFrame(GetDocument(),
                                     (CFrameWnd*)AfxGetMainWnd());
      ASSERT(pNewFrame);

      // Activate the frame and set its active view
      pDocTemplate->InitialUpdateFrame(pNewFrame, NULL);

      CYourView* pWBVw = (CYourView*)pNewFrame->GetActiveView();
      ASSERT(pWBVw);

      *ppDisp = pWBVw->m_webBrowser.GetApplication();
   }

REFERENCES
"Reusing the WebBrowser and MSHTML" in the Internet Client SDK Help:


   http://www.microsoft.com/msdn/sdk/inetsdk/help/

(c) Microsoft Corporation 1998, All Rights Reserved. Contributions by Scott Roberts, Microsoft Corporation
 



--------------------------------------------------------------------------------
Additional query words: window.open
Keywords : kbWebBrowser
Technology : ole internet kbInetDev
Version : WINDOWS:4.0,4.01
Platform : WINDOWS
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.  

Last reviewed: October 15, 1998
) 1998 Microsoft Corporation. All rights reserved. Terms of Use.


0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1525072
Let me see, you gave me a D??
0
 

Author Comment

by:vogtster
ID: 1525073
It did not work.  Kept getting errors.  So I am trapping the window.open in the data stream, getting the file name, and then just doing a navigate to another web browser control on another form and making the form visible.

Did you get your points?  I hope so.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

664 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question