javascript - 在 SweetAlert 中显示视频

标签 javascript php html sweetalert vue-sweetalert2

下午好,我正在使用 SweetAlert 来显示通知,查看官方 SweetAlert 文档,他们显示了一些示例,例如显示图像,但我想做的是显示 YouTube 视频。

SweetAlert2

Swal.fire({
  title: 'Sweet!',
  text: 'Modal with a custom image.',
  imageUrl: 'https://unsplash.it/400/200',
  imageWidth: 400,
  imageHeight: 200,
  imageAlt: 'Custom image',
})

任何在 SweetAlert 上显示 Youtube 视频的建议。

我做过的一些例子是用 iframe 嵌入视频:

<iframe width="560" height="315" src="https://www.youtube.com/embed/d_elXY2Lcfk" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

但我希望只需放置路径就可以看到视频。

最佳答案

在文档中,您可以使用自定义html作为警报正文

Swal.fire({
  title: '<strong>HTML <u>example</u></strong>',
  icon: 'info',
  html:
    '<iframe width="560" height="315" src="https://www.youtube.com/embed/d_elXY2Lcfk" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>',
  showCloseButton: true,
  showCancelButton: true,
  focusConfirm: false,
  confirmButtonText:
    '<i class="fa fa-thumbs-up"></i> Great!',
  confirmButtonAriaLabel: 'Thumbs up, great!',
  cancelButtonText:
    '<i class="fa fa-thumbs-down"></i>',
  cancelButtonAriaLabel: 'Thumbs down'
})

关于javascript - 在 SweetAlert 中显示视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65854871/

相关文章:

php - preg_last_error() 看似有错误却说没有错误

html - CSS类名长度会影响浏览器性能吗?

html - 如何更改 Eclipse 中 CSS 和 HTML 的默认设置

javascript - Canvas 中的动画不起作用

javascript - 即使在网站中使用 JavaScript 阻止弹出窗口时如何共享 Twitter

javascript - 在 D3 v5 JS 中读取 CSV : Why am I having trouble grabbing data?

html - 在同一行中放置 2 个 div

javascript - 为 JSON 数据传输选择合适的压缩方案

PHP 1x while 2x for 循环极大地减慢了加载速度

php - Python 等价于 PHP include