回答編集履歴
1
見直しキャンペーン中
answer
CHANGED
@@ -1,71 +1,72 @@
|
|
1
|
-
`target="_blank"`でも無視して遷移します。
|
2
|
-
`teratail`が入っていないURLは規定ブラウザで開きます。
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
<a href="/
|
7
|
-
|
8
|
-
|
9
|
-
<a href="http://leverages.jp/
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
using Microsoft.Web.WebView2.
|
15
|
-
using
|
16
|
-
using System
|
17
|
-
using System.
|
18
|
-
using System.
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
webView2.
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
}
|
1
|
+
`target="_blank"`でも無視して遷移します。
|
2
|
+
`teratail`が入っていないURLは、規定ブラウザで開きます。
|
3
|
+
|
4
|
+
フッターにある↓が確認にいいでしょう。
|
5
|
+
```html
|
6
|
+
<a href="http://blog.teratail.com/" target="_blank">公式ブログ</a>
|
7
|
+
<a href="/report" target="_blank">teratail Report</a>
|
8
|
+
|
9
|
+
<a href="http://leverages.jp/" target="_blank">運営会社</a>
|
10
|
+
<a href="http://leverages.jp/privacypolicy/" target="_blank">個人情報保護方針</a>
|
11
|
+
```
|
12
|
+
|
13
|
+
```cs
|
14
|
+
using Microsoft.Web.WebView2.Core;
|
15
|
+
using Microsoft.Web.WebView2.WinForms;
|
16
|
+
using System;
|
17
|
+
using System.Diagnostics;
|
18
|
+
using System.Threading.Tasks;
|
19
|
+
using System.Windows.Forms;
|
20
|
+
|
21
|
+
namespace Questions320460
|
22
|
+
{
|
23
|
+
public partial class Form1 : Form
|
24
|
+
{
|
25
|
+
private WebView2 webView2;
|
26
|
+
|
27
|
+
public Form1()
|
28
|
+
{
|
29
|
+
InitializeComponent();
|
30
|
+
webView2 = new WebView2
|
31
|
+
{
|
32
|
+
Source = new Uri("https://teratail.com/questions/320460"),
|
33
|
+
Dock = DockStyle.Fill,
|
34
|
+
};
|
35
|
+
webView2.NavigationStarting += WebView2_NavigationStarting;
|
36
|
+
|
37
|
+
Controls.Add(webView2);
|
38
|
+
|
39
|
+
_ = InitializeAsync();
|
40
|
+
}
|
41
|
+
|
42
|
+
private async Task InitializeAsync()
|
43
|
+
{
|
44
|
+
await webView2.EnsureCoreWebView2Async(null); // CoreWebView2初期化待ち
|
45
|
+
webView2.CoreWebView2.NewWindowRequested += CoreWebView2_NewWindowRequested;
|
46
|
+
}
|
47
|
+
|
48
|
+
private void WebView2_NavigationStarting(object sender, CoreWebView2NavigationStartingEventArgs e)
|
49
|
+
{
|
50
|
+
if (!e.Uri.Contains("teratail"))
|
51
|
+
{
|
52
|
+
e.Cancel = true; // Navigationのキャンセル
|
53
|
+
Process.Start(e.Uri);
|
54
|
+
return;
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
private void CoreWebView2_NewWindowRequested(object sender, CoreWebView2NewWindowRequestedEventArgs e)
|
59
|
+
{
|
60
|
+
e.Handled = true; // NewWindowのキャンセル
|
61
|
+
|
62
|
+
if (!e.Uri.Contains("teratail"))
|
63
|
+
{
|
64
|
+
Process.Start(e.Uri);
|
65
|
+
return;
|
66
|
+
}
|
67
|
+
|
68
|
+
webView2.CoreWebView2.Navigate(e.Uri); // 既存WebView2で遷移
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|
71
72
|
```
|