简体   繁体   English

如何在lightswitch应用程序中打开浏览器窗口?

[英]How to open browser window in lightswitch application?

I want to open browser window instead of new tab in current/default browser. 我想打开浏览器窗口,而不是在当前/默认浏览器中打开新标签。

I am using this code in desktop client on screen command button click event. 我在屏幕命令按钮单击事件的桌面客户端中使用此代码。

            Microsoft.LightSwitch.Threading.Dispatchers.Main.BeginInvoke(() =>
            { 
                if (AutomationFactory.IsAvailable)
                {
                    dynamic shell = AutomationFactory.CreateObject("Shell.Application");

                    shell.ShellExecute("http://localhost:55722/Home/Index");
                }
                else if (!System.Windows.Application.Current.IsRunningOutOfBrowser)
                {
                    HtmlPage.Window.Navigate(new Uri("http://localhost:55722/Home/Index"), "_blank");
                }
                else
                {
                    throw new InvalidOperationException();
                }
            });

This code is opening my page in current/opened browser tab. 该代码正在当前/打开的浏览器选项卡中打开我的页面。

Can you please advice how to open browser window in desktop client on screen command button click event. 您能否建议屏幕命令按钮单击事件时如何在桌面客户端中打开浏览器窗口。

Your answer will appreciable! 您的答案将不胜感激! :) :)

Thanks, 谢谢,

Jatin Jatin

I tried this with IE and it opens a new window each time: 我用IE尝试过,每次都会打开一个新窗口:

dynamic shell = AutomationFactory.CreateObject("WScript.Shell");
shell.Run("iexplore.exe", 1, true);

Other browsers may work, but some may require command line arguments to open a new window every time. 其他浏览器可能会运行,但有些浏览器可能需要命令行参数才能每次打开新窗口。 See Open a browser window as a pop under in C# for a Chrome example. 有关Chrome的示例,请参见在C#中弹出方式打开浏览器窗口

To detect the default browser, you could read from the appropriate location in the registry, as shown in Access registry from Silverlight OOB . 若要检测默认浏览器,可以从注册表中的适当位置读取,如Silverlight OOB的Access注册表中所示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM