Click here to Skip to main content
15,895,142 members
Home / Discussions / C#
   

C#

 
QuestionAdding a variable to a variable name Pin
MichCl13-Jun-12 8:35
MichCl13-Jun-12 8:35 
AnswerRe: Adding a variable to a variable name Pin
Pete O'Hanlon13-Jun-12 8:41
mvePete O'Hanlon13-Jun-12 8:41 
GeneralRe: Adding a variable to a variable name Pin
MichCl13-Jun-12 8:57
MichCl13-Jun-12 8:57 
GeneralRe: Adding a variable to a variable name Pin
Dave Kreskowiak13-Jun-12 9:18
mveDave Kreskowiak13-Jun-12 9:18 
AnswerRe: Adding a variable to a variable name Pin
BobJanova14-Jun-12 2:06
BobJanova14-Jun-12 2:06 
GeneralRe: Adding a variable to a variable name Pin
MichCl14-Jun-12 6:37
MichCl14-Jun-12 6:37 
GeneralRe: Adding a variable to a variable name Pin
Pete O'Hanlon14-Jun-12 7:05
mvePete O'Hanlon14-Jun-12 7:05 
QuestionIWebBrowser2 NewWindow3 doesn't track target frame name Pin
vwmberry9513-Jun-12 7:11
vwmberry9513-Jun-12 7:11 
I've implemented a tabbed browser that inherits from IWebBrowser2 and takes advantage of the BeforeNavigate2 and NewWindow3 events. When navigating to a new window, the event is trapped and the new window is sent to a new tab.

C#
using System;
using System.Windows.Forms;

namespace BrowserTests
{
    public partial class CustomBrowser : Form
    {
        public CustomBrowser()
        {
            InitializeComponent();
        }

        private void CustomBrowser_Load(object sender, EventArgs e)
        {
            this.CreateTabBrowser();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // Navigate the current window to the given URL
            (this.tabControl1.SelectedTab.Tag as WebBrowser).Navigate(this.textBox1.Text);
        }

        private WebBrowser CreateTabBrowser()
        {
            // Create a new tab, add it, and select it
            TabPage tab = new TabPage();
            this.tabControl1.TabPages.Add(tab);
            this.tabControl1.SelectedTab = tab;

            // Create a new browser
            WebBrowser web = new WebBrowser()
            {
                Parent = tab,
                Dock = DockStyle.Fill,
                Tag = tab
            };

            tab.Tag = web;

            // Wire the events
            SHDocVw.WebBrowser axWeb = (SHDocVw.WebBrowser)web.ActiveXInstance;
            axWeb.BeforeNavigate2 += new SHDocVw.DWebBrowserEvents2_BeforeNavigate2EventHandler(axWeb_BeforeNavigate2);
            axWeb.NewWindow3 += new SHDocVw.DWebBrowserEvents2_NewWindow3EventHandler(axWeb_NewWindow3);

            return web;
        }

        void axWeb_BeforeNavigate2(object pDisp, ref object URL, ref object Flags, ref object TargetFrameName, ref object PostData, ref object Headers, ref bool Cancel)
        {
            // Do checks here
        }

        void axWeb_NewWindow3(ref object ppDisp, ref bool Cancel, uint dwFlags, string bstrUrlContext, string bstrUrl)
        {
            // Create a new tab browser
            WebBrowser web = this.CreateTabBrowser();
            SHDocVw.WebBrowser axWeb = (SHDocVw.WebBrowser)web.ActiveXInstance;

            // Point to the new tab browser
            ppDisp = axWeb.Application;
        }

    }
}


Some pages are trying to navigate to a new window marked as a frame: Site With Example Behavior
(second link is what I'm trying to replicate). Click the link, it opens a new window/tab... switch windows/tabs, click the same link, it should now navigate to the other window/tab that was just created. However, since each tab window is a new browser, the pages cannot find the frame to navigate to and it results in a new window every time, not just the first time.

I've tried the following modification but I don't have a reference to the new window's frame name...

C#
void axWeb_NewWindow3(ref object ppDisp, ref bool Cancel, uint dwFlags, string bstrUrlContext, string bstrUrl)
{
    foreach (TabPage tabPage in this.tabControl1.TabPages)
    {
        WebBrowser web = (WebBrowser)tabPage.Tag;
        SHDocVw.WebBrowser axWeb = (SHDocVw.WebBrowser)web.ActiveXInstance;

        if (web.Document.Window.Name == "targetFrameName")
        {
            ppDisp = axWeb.Application;
            this.tabControl1.SelectedTab = tabPage;
            return;
        }
    }

    // Create a new tab browser
    WebBrowser web = this.CreateTabBrowser();
    SHDocVw.WebBrowser axWeb = (SHDocVw.WebBrowser)web.ActiveXInstance;

    ppDisp = axWeb.Application;
}


If I hard code the name of the target frame on various sites that I know of, the navigation gets sent to the existing frame like it should and does not create a new window.

Anyone know how I can get the target frame name of a new window?

Thanks!
QuestionPHP web service requires array but how to send correct array with C#? Pin
JD8613-Jun-12 7:01
JD8613-Jun-12 7:01 
AnswerMessage Closed Pin
13-Jun-12 8:51
WebMaster13-Jun-12 8:51 
GeneralRe: PHP web service requires array but how to send correct array with C#? Pin
JD8613-Jun-12 12:42
JD8613-Jun-12 12:42 
AnswerRe: PHP web service requires array but how to send correct array with C#? Pin
BobJanova14-Jun-12 2:08
BobJanova14-Jun-12 2:08 
GeneralRe: PHP web service requires array but how to send correct array with C#? Pin
JD8614-Jun-12 2:57
JD8614-Jun-12 2:57 
GeneralRe: PHP web service requires array but how to send correct array with C#? Pin
BobJanova14-Jun-12 3:51
BobJanova14-Jun-12 3:51 
GeneralRe: PHP web service requires array but how to send correct array with C#? Pin
JD8614-Jun-12 3:56
JD8614-Jun-12 3:56 
GeneralRe: PHP web service requires array but how to send correct array with C#? Pin
BobJanova14-Jun-12 5:54
BobJanova14-Jun-12 5:54 
GeneralRe: PHP web service requires array but how to send correct array with C#? Pin
JD8614-Jun-12 5:57
JD8614-Jun-12 5:57 
QuestionException has been thrown by the target of an invocation. Pin
MichCl13-Jun-12 6:01
MichCl13-Jun-12 6:01 
AnswerRe: Exception has been thrown by the target of an invocation. Pin
Pete O'Hanlon13-Jun-12 6:10
mvePete O'Hanlon13-Jun-12 6:10 
GeneralRe: Exception has been thrown by the target of an invocation. Pin
MichCl13-Jun-12 7:12
MichCl13-Jun-12 7:12 
Questioncheck if record already exists in database table Pin
Saidrex13-Jun-12 4:44
Saidrex13-Jun-12 4:44 
AnswerRe: check if record already exists in database table Pin
Eddy Vluggen13-Jun-12 4:53
professionalEddy Vluggen13-Jun-12 4:53 
GeneralRe: check if record already exists in database table Pin
Saidrex13-Jun-12 5:16
Saidrex13-Jun-12 5:16 
AnswerRe: check if record already exists in database table Pin
Pete O'Hanlon13-Jun-12 4:55
mvePete O'Hanlon13-Jun-12 4:55 
GeneralRe: check if record already exists in database table Pin
Saidrex13-Jun-12 5:17
Saidrex13-Jun-12 5:17 

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

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