找回密码
 快速注册
搜索
查看: 76|回复: 3

粘贴上传图片

[复制链接]

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2022-7-15 02:48 |阅读模式
本帖最后由 hbghlyj 于 2023-5-2 10:43 编辑 CodePen – HTML5 paste image to page


在文本框粘贴上传图片,例如MyBB从v. 1.8.22开始支持图片粘贴上传.
例如phpBB插件(GitHub)
例如Discuz插件(Discuz disgusts me)
例如GitHub的讨论区的编辑框.
例如SnipNote, textbox.io, Google Docs


(mybb)
(phpbb)
(Comparison of Internet forum software)

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2022-8-28 03:31
pasteboard.co/
Super simple and lightning fast image sharing. Upload clipboard images with Copy & Paste and image files with Drag & Drop.

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2022-9-3 06:44
Interact with the clipboard
Clipboard.read()
  1. const destinationImage = document.querySelector('#destination')
  2. destinationImage.addEventListener('click', pasteImage);
  3. async function pasteImage() {
  4.   try {
  5.     const permission = await navigator.permissions.query({ name: 'clipboard-read' });
  6.     if (permission.state === 'denied') {
  7.       throw new Error('Not allowed to read clipboard.');
  8.     }
  9.     const clipboardContents = await navigator.clipboard.read();
  10.     for (const item of clipboardContents) {
  11.       if (!item.types.includes('image/png')) {
  12.         throw new Error('Clipboard contains non-image data.');
  13.       }
  14.       const blob = await item.getType('image/png');
  15.       destinationImage.src = URL.createObjectURL(blob);
  16.     }
  17.   }
  18.   catch (error) {
  19.     console.error(error.message);
  20.   }
  21. }
复制代码

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2023-5-2 17:26
DiscuzX issue

popcorner
member
an hour ago

此功能计划在未来的新版编辑器中提供。
当前版本的编辑器没有添加这种功能的计划,但应用中心有支持此功能的第三方插件。可以在应用中心的论坛试用此效果。

手机版|悠闲数学娱乐论坛(第3版)

GMT+8, 2025-3-4 15:44

Powered by Discuz!

× 快速回复 返回顶部 返回列表