问题
I used some little basic javascript code and used it to make a simple UWP app, the alert function in the code works when i run the file in the browser, but it doesnt work when i try it in UWP app. below is the code
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>App6</title>
<!-- WinJS references -->
<link href="WinJS/css/ui-dark.css" rel="stylesheet" />
<script src="WinJS/js/base.js"></script>
<script src="WinJS/js/ui.js"></script>
<!-- App6 references -->
<link href="/css/default.css" rel="stylesheet" />
<script src="/js/default.js"></script>
</head>
<body class="win-type-body" onload="alert('oh yeah');">
</body>
</html>
回答1:
The alert function is not supported in UWP app context. You have to use
var dialog = new Windows.UI.Popups.MessageDialog("Hello");
dialog.showAsync();
https://msdn.microsoft.com/library/windows/apps/br208674?cs-save-lang=1&cs-lang=javascript#code-snippet-1
来源:https://stackoverflow.com/questions/33439818/javascript-alert-function-not-working-in-uwp-app