![](/img/trans.png)
[英]Quill rich text editor resize image only works in IE but not in Chrome or Edge
[英]JS copying rich text from IE/Microsoft Edge
我的網站上有一個按鈕,期望當單擊該按鈕時,應將一大塊富文本(html 格式)復制到用戶的剪貼板,以便他們可以將其粘貼到支持富文本的編輯器(即展望)與格式。
我通過使用多種不同的方法(例如使用clipboard.js
或clipboard-polyfill.js
,或執行如下所示的本機復制命令)使其在 Chrome/FF 中工作:
function copyToClip(str) {
function listener(e) {
e.clipboardData.setData("text/html", htmlstr);
e.preventDefault();
}
document.addEventListener("copy", listener);
document.execCommand("copy");
document.removeEventListener("copy", listener);
};
但是,上述方法均不適用於 Microsoft Edge 或 IE 。 我想知道是否有可能在 Edge/IE 中實現目標,如果是,我該怎么做?
PS 我想盡可能避免使用 ZeroClipboard.js,因為它需要用戶安裝/啟用 Flash。
謝謝
這與 Internet Explorer 配合良好
function paste() {
//internet explorer
var value = window.clipboardData.getData("Text");
document.getElementById("Text1").value = value;
}
我使用了 Microsoft Edge 版本 83.0.478.45(官方版本)(64 位)。我嘗試使用此代碼,它對我有用。
function CopyToClipboard() {
var controlValue = "Assign Your Data";
var textare = document.createElement('textarea');
textare.textContent = controlValue;
textare.style.position = "fixed";
document.body.appendChild(textare);
textare.focus();
textare.select();
try {
window.focus();
navigator.clipboard.writeText(textare.textContent);
}
catch (error) {
console.error(error);
}
finally {
document.body.removeChild(textare);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.