小编Ale*_*lex的帖子

使用脚本标签模拟XMP标签并允许复制内容

正式<xmp></xmp>不推荐使用(但仍受主要浏览器支持),因此要对新应用程序合法,唯一的解决方法是替换xmp标记(不解析HTML的标记),就像我发现的那样:<script type="text/plain">...</script>

此解决方案一切正常,但Firefox( Firefox )阻止复制/粘贴<script type="text/plain"></script>标记中包含的内容。

要求修复bugzilla可能需要10到15年的时间,因为类似的firefox问题无法从禁用的text / textarea元素复制内容,所以我在这里问,可能是有人得到一些解决方法以允许复制/粘贴包含在内容中<script type="text/plain">...</script>或可能存在更好的xmp标记替换方法,以与当今的浏览器和规则兼容。

以下是示例,我如何使用 <script type="text/plain">...</script>

<!doctype html>
<html lang="en">
<head>
  <title>Attempt to emulate depricated XMP tag</title>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <style>
    script[type="text/plain"] {
      display: block;
      width: 100%;
      white-space: pre;
      box-sizing: border-box;
      user-select:text !important;
    }
  </style>
</head>

<body>

<script type="text/plain" readonly>
  Try to select then copy and paste me somewhere else ...
    and you will fail... …
Run Code Online (Sandbox Code Playgroud)

html css firefox html5 css3

6
推荐指数
0
解决办法
112
查看次数

标签 统计

css ×1

css3 ×1

firefox ×1

html ×1

html5 ×1