简体   繁体   English

HTML5 ContentEditable添加视频

[英]Html5 contenteditable add video

So with html5's contenteditable feature, you can embed images with javascript... What about videos? 因此,借助html5的contenteditable功能,您可以使用javascript嵌入图像...视频呢? Any ideas? 有任何想法吗? I don't know where to start. 我不知道从哪里开始。 Thank you. 谢谢。

The fiddle that you posted uses the execCommand function to change the formatting of the contenteditable region. 您发布的小提琴使用execCommand函数来更改contenteditable区域的格式。 To insert an image, it uses the insertImage command. 要插入图像,它使用insertImage命令。 A full list of commands can be found here under Commands . 完整的命令列表可在“ 命令”下找到。

There are no predefined commands for inserting videos, which makes sense as: 没有用于插入视频的预定义命令,这很有意义:

  1. Different video formats need different wrappers 不同的视频格式需要不同的包装
  2. The code required for creating each type of video wrapper would be cumbersome and probably superfluous to most people 创建每种类型的视频包装程序所需的代码很麻烦,对于大多数人来说可能是多余的
  3. There is no fully implemented standard way of imbedding videos on a page (like there is with embedding images, through the <img> tag 没有完全实现的将视频嵌入页面上的标准方法(就像通过<img>标签嵌入图像一样)

Regardless, there is a command there called insertHTML which: 无论如何,那里有一个名为insertHTML的命令,该命令:

Inserts an HTML string at the insertion point (deletes selection). 在插入点插入HTML字符串(删除选择)。 Requires a valid HTML string to be passed in as a value argument. 需要将有效的HTML字符串作为值参数传递。

So while it won't work out of the box, you could, in theory, create your own solution that uses the insertHTML command: 因此,尽管它无法立即使用, insertHTML理论上讲,您可以使用insertHTML命令创建自己的解决方案:

  1. Prompt user for video url 提示用户输入视频网址
  2. Determine format of video through extension 通过扩展名确定视频格式
  3. Create a dynamic HTML string that includes the correct video wrapper, possibly by matching the format to an array and returning the basic string 创建一个包含正确的视频包装器的动态HTML字符串,方法可能是将格式与数组匹配,然后返回基本字符串
  4. Make sure the string is value 确保字符串是值
  5. Use insertHTML to inset the string at the cursor location 使用insertHTML在光标位置插入字符串

I haven't tested this, however, so as far as I know embedding videos in contenteditable could be altogether impossible. 不过,我尚未对此进行测试,据我所知,将视频嵌入到contenteditable可能是完全不可能的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM