如何复制警报框的文本 [英] How to copy text of alert box

查看:56
本文介绍了如何复制警报框的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的代码将文档的路径写入警告框。

I write the path of a document into the alert box via using below code.

var oArg = new Object();
oArg.Document = $(t).attr("path") + str + "/" + $(t).attr("name");
alert(oArg.Document);

假设消息为: documents / files / img / stack.jpg

我只想用一个按钮复制这个文本。对于Chrome,Ctrl + C可以正常使用但是对于IE,Ctrl + C会复制警报框中的所有内容。

I only want to copy this text with a button. For Chrome Ctrl + C is ok for it but for IE, Ctrl + C copies everything at the alertbox.

如何使用按钮仅复制邮件?

How can I copy only the message with using a button?

Ctrl + C的工作原理如下:

Ctrl + C works like below:


  • Chrome - 完美无缺。

  • Internet Explorer - Works,但您可以获得额外的文本。标题和确定按钮文本也会被复制,还有一串破折号。这几乎不是你想要的。

  • Firefox - 根本不起作用您必须先选择文本才能复制它。

推荐答案

你可以做的是提示用户提供文字,然后问他们复制它。因此:

What you can do, is to prompt the user with the text, and ask them for copy it. As such:

prompt("Copy to clipboard: Ctrl+C, Enter", oArg.Document);

因为如果您向提示提供文本,它会自动被选中。这适合你吗?

Because if you supply a text to the prompt, it automatically gets selected. Does this suits you?

这篇关于如何复制警报框的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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