【问题标题】:External links are not opening in default browser while using VSTO 2016 word addin使用 VSTO 2016 word 插件时,外部链接未在默认浏览器中打开
【发布时间】:2021-10-13 14:33:25
【问题描述】:

我在任务窗格中使用了 2016 VSTO 插件这个词。

在任务窗格中,我打开了我的网站的 URL,其中有一些外部超链接。

我的默认浏览器是谷歌浏览器,但外部链接仍然在 IE 中打开。

我尝试使用以下网址。

https://answers.microsoft.com/en-us/msoffice/forum/all/office-wont-open-hyperlinks-in-default-browser/d856aeff-081b-4e26-9626-40b23bf3de42

下面这个网址是说不可能的

How to set the default browser in word addin

任何帮助将不胜感激。

谢谢

【问题讨论】:

    标签: ms-word vsto word-addins


    【解决方案1】:

    在任务窗格中,您可以使用LinkLabel 控件,该控件允许处理对链接的点击,并通过以下方式以编程方式运行系统的默认网络浏览器:

        public void InitializeLinkControl()
        {
            // Create the LinkLabel.
            this.linkLabel1 = new System.Windows.Forms.LinkLabel();
    
            // Configure the LinkLabel's location. 
            // this.linkLabel1.Location = new System.Drawing.Point(34, 56);
            // Specify that the size should be automatically determined by the content.
            this.linkLabel1.AutoSize = true;
    
            // Add an event handler to do something when the links are clicked.
            this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);
    
            // Set the text for the LinkLabel.
            this.linkLabel1.Text = "Visit Microsoft";
        }
    
        private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
        {
            // Specify that the link was visited.
            this.linkLabel1.LinkVisited = true;
    
            // Navigate to a URL.
            System.Diagnostics.Process.Start("http://www.microsoft.com");
        }
    

    【讨论】:

    • 感谢您的回复,但我们没有在 taspane 方面编写代码,我们只是提供我们的网站 URL 以在任务窗格中打开,并且我们网站中的外部链接代码具有带有 target="_blank 的超链接"。
    • 您在任务窗格上使用哪种浏览器?
    • 浏览器也允许处理超链接点击,所以你可以做同样的方法。
    • 在我的网站中,我有 example.com" target="_blank">支持此代码,并且我正在使用 WebBrowser 的任务窗格。
    • 使用任务窗格上的WebView2 浏览器控件或/和处理代码中的超链接点击。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-27
    • 2013-11-29
    • 2012-07-18
    • 1970-01-01
    • 2012-11-29
    • 1970-01-01
    • 2014-04-24
    相关资源
    最近更新 更多