问题
I am building an Office add-in to copy the URL of the opened Office document to the Windows clipboard.
But it doesn't work. Please let me know what my code is wrong.
Here's my FunctionFile.html
for UI-less Office add-in.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--During development turn off caching-->
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
<title></title>
<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js" type="text/javascript"></script>
<script>
// The initialize function must be run each time a new page is loaded
(function () {
Office.initialize = function (reason) {
};
})();
function copyLink(event) {
Office.context.document.getFilePropertiesAsync(function (asyncResult) {
navigator.clipboard.writeText(asyncResult.value.url);
});
event.completed();
}
</script>
</head>
<body>
Function file body is never displayed.
</body>
</html>
I tried this using execCommands, but it was not working as well.
来源:https://stackoverflow.com/questions/65149982/how-to-copy-url-to-windows-clipboard-in-office-add-in