How to get the Query String parameters, in a new tab, from the IEModule loaded into that tab?

Add-in Express™ Support Service
That's what is more important than anything else

How to get the Query String parameters, in a new tab, from the IEModule loaded into that tab?
 
Jonathan Gilpin




Posts: 50
Joined: 2012-12-11
Hi Guys,
Any thoughts on how to get the query string parameters of a url loaded in a new window/process?

Here is the flow of my IE Addon:

1.)Open IE for the first time and the first ADXIEModule instance is instantiated/loaded.
2.)The first ADXIEModule instance will call IEApp.Navigate(newUrlWithQueryStringParams, ref flags, target); //where object flags = null; object target = "_blank";
3.)Now a new tab opens, which instantiates a second ADXIEModule instance.

From the *second* ADXIEModule instance, how can I know the query string parameters?
BeforeNavigate2 event does not fire in the second instance..but only the first instance.

I'm looking for a way to identify from the second instance, that it was the one opened by original Navigate call.

Any thoughts on how to do this?
Posted 08 Jul, 2013 18:09:04 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Jonathan,

Please try the code below:

        private string targetURL = String.Empty;

        public string GetTargetURL()
        {
            string _temp = this.targetURL;
            this.targetURL = String.Empty;

            return _temp;
        }

        private void adxieContextMenuCommandItem2_OnClick(object sender, object htmlElement)
        {
            object flags = null; object target = "_blank";
            this.targetURL = "//www.add-in-express.com/forum/read.php?FID=10&TID=11737&MID=59783#message59783";

            IEApp.Navigate("about:blank?threadID=" + this.ThreadID.ToString() + "&processID=" + this.ProcessID.ToString(), ref flags, target);
        }

        private void IEModule_DocumentComplete(object pDisp, string url)
        {
            if (!String.IsNullOrEmpty(url))
            {
                if (url.StartsWith("about:blank?threadID=", StringComparison.InvariantCultureIgnoreCase))
                {
                    int tabThreadID = 0;
                    int tabProcessID = 0;

                    try
                    {
                        string callerIDs = url.Replace("about:blank?", String.Empty);
                        string[] parts = callerIDs.Split('&');
                        tabThreadID = int.Parse(parts[0].Replace("threadID=", String.Empty));
                        tabProcessID = int.Parse(parts[1].Replace("processID=", String.Empty));
                    }
                    catch (Exception)
                    {
                    }

                    if (tabThreadID != 0 && tabProcessID != 0)
                    {
                        string newUrlWithQueryStringParams = String.Empty;

                        ArrayList modules = ADXIEModule.GetModulesByTypeName(this.GetType().FullName);
                        foreach (ADXIEModule m in modules)
                        {
                            if (m.ThreadID == tabThreadID && m.ProcessID == tabProcessID)
                            {
                                newUrlWithQueryStringParams = ((IEModule)m).GetTargetURL();
                                break;
                            }
                        }

                        if (!String.IsNullOrEmpty(url))
                        {
                            object flags = null; object target = "_self";
                            IEApp.Navigate(newUrlWithQueryStringParams, ref flags, target);
                        }
                    }
                }
            }
        }
Posted 09 Jul, 2013 10:41:43 Top
Jonathan Gilpin




Posts: 50
Joined: 2012-12-11
Thanks Sergey, I'll give it a shot!
Posted 09 Jul, 2013 10:56:30 Top
Jonathan Gilpin




Posts: 50
Joined: 2012-12-11
Seems to be a typo:

this.targetURL = ";;

is that meant to be this.targetURL = ";;" ? or this.targetURL = ""; ?
Posted 09 Jul, 2013 11:07:29 Top
Jonathan Gilpin




Posts: 50
Joined: 2012-12-11
Thanks Sergey, this will work perfectly!

The reason DocumentComplete never fired on the newly opened form, was because of the redirect that page is doing. Opening to about:blank first allows the load to finish..thereby firing DocumentComplete, which has all the query string parameters.

Thank you so much!

Jon
Posted 09 Jul, 2013 11:32:04 Top