使用脚本标签模拟XMP标签并允许复制内容 [英] Emulate XMP tag with script tag and allow to copy content

查看:112
本文介绍了使用脚本标签模拟XMP标签并允许复制内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<xmp></xmp>官方已弃用(但仍受主要浏览器支持),因此要在新应用程序上合法使用,唯一的解决方法是使用xmp标记(不解析HTML的标记)正如我发现的那样:<script type="text/plain">...</script>.

Officially <xmp></xmp> is deprecated (but still supported by major browsers), so to be on the lawful side for new applications the only workaround is to replace xmp tag (that don't parse HTML's tags) is to use as I found: <script type="text/plain">...</script>.

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

Everything is Ok with this solution, but Firefox (ONLY) preventing to copy/paste content enclosed in <script type="text/plain"></script> tag.

要求修复bugzilla可能需要10到15年的时间,因为类似的Firefox问题,当一个无法从禁用的文本/文本区域元素中复制内容,所以我在这里问,也许有人可以通过某种解决方法来允许复制/粘贴包含在<script type="text/plain">...</script>中的内容,或者可能还有更好的方法xmp替换标签以与当今的浏览器和规则兼容.

Asking to fix it on bugzilla may takes 10-15 years as it is with similar firefox's issue, when one can't copy content from disabled text/textarea elements, so I asking here, may be someone get some workaround to allow copy/paste content enclosed in <script type="text/plain">...</script> or may be there is something better xmp tag replacement to be compatible with nowadays browsers and rules.

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

Below is example, how I'm using <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...
      WITH FireFox ONLY !!!

 <p>raw HTML tag "p" here for example</p>
</script>

</body>
</html>

P.S.

为防止要约使用<pre>或其他修改原始内容(转换为HTML实体)的解决方案,我应该说-对我来说不起作用,我必须将原始原始内容包含在<script>标记内.

To prevent offers to use <pre> or other solutions that modified original content (converting to HTML entities) I should say, - it won't work for me, I have to have original raw content inside <script> tag.

推荐答案

好吧,我会回答我自己的问题:

Well, I will answer my own question:

我向mozilla报告了此问题是一个错误,该错误已被接受并很快解决了(非常感谢!!!).所描述的问题已在Firefox中修复,并且其行为与所有其他从版本68开始的受支持的浏览器的行为相同,因此,现在保存使用<script>标记代替<xmp>标记即可.

I reported to mozilla this issue as a bug and it was accepted and resolved pretty fast (Thanks a lot for that !!!). Described issue is fixed in Firefox and it will behave in the same manner as all other supported browsers beginning with version 68, so it save to use <script> tag as replacement for <xmp> tag now.

这篇关于使用脚本标签模拟XMP标签并允许复制内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆