我在电子网页视图中加载了一个外部网址。
我需要附加一个eventhandler来点击由某个类标记的元素。处理程序应在托管页面的上下文中执行,类似于示例中的eventhandler loadstart。 这可能吗?
<!DOCTYPE html>
<html>
<head>
<title>Hello World!</title>
</head>
<body>
<h1>Some eventhandler test</h1>
<div class="indicator" >
</div>
<div id="content" ></div>
<webview id="cmsWebview" src="http:///www.stackoverflow.com" style="height:100vh;display: flex;"></webview>
<script>
onload = function() {
var webview = document.getElementById("cmsWebview");
var indicator = document.querySelector(".indicator");
var loadstart = function() {
indicator.innerText = "loading...";
}
var loadstop = function() {
indicator.innerText = "...finished loading";
}
webview.addEventListener("did-start-loading", loadstart);
webview.addEventListener("did-stop-loading", loadstop);
}
</script>
</body>
</html>