function Copy() // this function will be latched to a button later on.
{
var text = writePreview(); // this pours in the formatted string by the writePreview() function to the variable 'text'
text = br2nl(text); //variable 'text' is purified from <br/> and is replaced by a carriage return
//I need some code here to pour in the contents of the variable 'text' to the clipboard. That way the user could paste the processed data to a 3rd party application
}
我正在構建一個離線的客戶端Web應用程序。這樣做的主要目的是讓用戶輸入字段,格式化文本使其符合特定條件,然後單擊複製,以便將其粘貼到第三方CRM。如何使用JavaScript將變量的內容放入剪貼板?
唯一可用的瀏覽器是Google Chrome。我搜索了互聯網,希望找到一個簡單的解決方案。
我不關心安全性,因爲這個應用程序不會被髮布,只是爲了脫機使用。
我想保持它儘可能簡單,並添加不可見的textarea破壞佈局。我目前的環境中不允許使用Flash。
可能重複[如何在JavaScript中複製到剪貼板?](http://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript) –