-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainPage.xaml.cs
More file actions
46 lines (38 loc) · 1.42 KB
/
MainPage.xaml.cs
File metadata and controls
46 lines (38 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
45
46
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace WebViewScriptNotify
{
public sealed partial class MainPage
{
public MainPage()
{
this.InitializeComponent();
}
private async void WebView_OnNavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args)
{
await WebView.InvokeScriptAsync("eval", new[]
{
"var Anchors = document.getElementsByTagName(\"a\");" +
"for (var i = 0; i < Anchors.length ; i++) {" +
" Anchors[i].addEventListener(\"contextmenu\", " +
" function (event) {" +
" window.external.notify(this.href);" +
" }," +
" false);" +
"}"
});
}
private void WebView_OnScriptNotify(object sender, NotifyEventArgs e)
{
var pointer = Window.Current.CoreWindow.PointerPosition;
var url = e.Value;
TextBlockLink.Text = $"Pointer X({pointer.X}) | Y({pointer.Y}) -> url: {url}";
TextBlockLink2.Text = url;
Ppup.HorizontalOffset = pointer.X - 300;
Ppup.VerticalOffset = pointer.Y - 60;
Ppup.IsOpen = true;
}
}
}