向iframe复制到剪贴板的问题 [英] Issue with copy to clipboard for iframe

查看:140
本文介绍了向iframe复制到剪贴板的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想知道复制到剪贴板是否适用于iframe.我试图在谷歌搜索,没有喜悦.有人可以请教吗?
提前谢谢.

好的,所以我有一个网站,并且已经有一个复制到剪贴板的选项,我使用Javascript代码可以正常工作,但是现在我有了iframe,复制到剪贴板的功能不再起作用.我有一个html网站.我有一个基于Web的页面(html框架格式),用于我们关于各种主题的文本文档文章.该页面分为三帧.就像这样的"http://www.w3schools.com/html/tryit.asp?filename=tryhtml_frame_mix".复制到剪贴板选项适用于主菜单中显示的文章.
代码是:

Hi All,

I was wondering if copy to clipboard is available for iframe. i tried to search on google and no joy. Could somebody please advise?
Thanks in advance.

Ok So I am having a website and there was already a copy to clipboard option for which i used Javascript code and that worked perfectly fine but now i have iframe and the copy to clipboard function does not work anymore. I have a html website. I have a web based page(html- frames format) for our text documents articles on various subjects. The page is made in three frames. It''s exactly like this "http://www.w3schools.com/html/tryit.asp?filename=tryhtml_frame_mix". The copy to clipboard optionis for the articles displayed in the main menu.
The code is:

<SPAN ID="copytext" STYLE="height:;width:;background-color:">
<p>Please do the following:<br />
                    1. Click on Edit > Preferences<br />
                    2. Select the Multimedia Trust (legacy) Category on left side of window<br />
                    3. Select 'Other Documents' under 'Trust Options' frame<br />
                    4. Select 'Permission for Adobe(R) Flash(R) Player is set to Prompt' in<br />
                    list box<br />
                    5. Change value for Change permission for selected multimedia player<br />
                    to: 'Always'<br />
                    6. Click 'OK'                  </p>
                  <p>Kind Regards,</p>
</SPAN> 
<TEXTAREA ID="holdtext" STYLE="display:none;">
</TEXTAREA>
 <BUTTON onClick="ClipBoard();">Copy to Clipboard</BUTTON>





<SCRIPT LANGUAGE="JavaScript">
 
function ClipBoard() 
{
 holdtext.innerText = copytext.innerText;
 Copied = holdtext.createTextRange();
 Copied.execCommand("RemoveFormat");
 Copied.execCommand("Copy");
 }
 
</SCRIPT>



对于iframe,我正在使用它:



For iframe i am using this :

<iframe src="text.txt" frameborder="0" scrolling="yes" height="400" width="650">
  Text file not found.
 </iframe>

推荐答案

网页上的任何内容都可以复制到剪贴板.

如果您想以编程方式进行操作,请:1)如果您确实需要,请三思而后行;通常,用户自己可以做得更好; 2)如果您果断地想要它,但仍然有问题,请回到您的问题,标记您的技术,语言和其他相关信息,并说明您到底想要什么,在什么背景下以及到底是什么问题;向我们展示您尝试的代码;在这种情况下,请使用上面的改善问题".

—SA
Anything on the Web page can be copied to the clipboard.

If you want to do it programmatically, 1) think twice if you really want it; normally, the users themselves can do it better; 2) if you are decisively want it and still have a problem, go back to your question, tag your technology, language and other relevant information and explain how exactly you want it, to what context, and what exactly the problem is; show us the code you tried; in this case, use "Improve question" above.

—SA


针对已澄清的问题:

为此,我将使用jQuery库,您可以从 http://docs.jquery.com/Downloading_jQuery [ ^ ].

这是一个jQuery插件,可以将任何数据复制到客户端的剪贴板: http://archive.plugins. jquery.com/project/clipboard [^ ].

另外,如果您需要复制iframe的内容,请理解,静态获取任何元素数据都无济于事,因为框架的实际内容位于单独的资源中.您需要先下载它,大概是通过Ajax下载.

请在最近的答案中查看演示jQuery技术的代码示例:使用JavaScript从iframe检索值 [ ^ ].

请记住,Ajax本质上是异步的,这对您有好处,因为您实际上并不希望在JavaScript中使用任何阻塞调用.在回调中执行剪贴板操作,如我的第一个代码示例所示.

祝你好运,
—SA
In response to clarified question:

For this purpose, I would use jQuery library which you can freely download from http://docs.jquery.com/Downloading_jQuery[^].

This is a jQuery plug-in good to copy any data to the client''s clipboard: http://archive.plugins.jquery.com/project/clipboard[^].

Also, if you need to copy the content of you iframe, please understand that getting any element data statically won''t help you, because the real content of the frame is places in a separate resource. You need to download it first, presumably via Ajax.

Please see my code samples where I demonstrated the jQuery techniques in my recent answer: using javascript retrieving value from iframe[^].

Remember that Ajax is asynchronous in its nature, and that''s good for you as you don''t really want to use any blocking calls in your JavaScript. Perform your clipboard operation in the callback, as it is shown in my first code sample.

Good luck,
—SA


这篇关于向iframe复制到剪贴板的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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