Home >Web Front-end >JS Tutorial >Copy the js code of the Input content_Support all browsers, fix the problem of Firefox3.5 and above_javascript skills

Copy the js code of the Input content_Support all browsers, fix the problem of Firefox3.5 and above_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:24:451040browse
Copy the js code of the Input content_Support all browsers, fix the problem of Firefox3.5 and above_javascript skills
But two lines of JS code are enough for IE6, and it is similar for IE7 and above. The only difference is that the security prompt is disgusting. If users see it, they must be suspicious;
But even Firefox, Chrome, etc. You are not allowed to copy;
I remember that there were codes in this area on the Internet before. I searched and found that they cannot be used in Firefox 3.5 or above. Finally, I found one. The code is quite complicated, so I don’t dare. use.
Finally, I really had no choice but to check the information and wrote one myself:
A few main points to understand:
1. For browsers such as Firefox, for security reasons, just use them directly Copying is not allowed;
2. In Flash, you can use System.setClipboard() to throw the content to the clipboard, and then let FLASH work under Firefox;
3. In Flash Player 10.0 Later, for security reasons, the content of System.setClipboard must be in FLASH;
4. ExternalInterface can be used to communicate with JS;
5. ExternalInterface must be quoted in flash8;
Default HTML code:
Copy code The code is as follows:






So, when designing, make the first judgment first. If it is IE, just use the default code, which is the least problematic. , if not, use a FLASH to overwrite the default button;
Copy the code The code is as follows:

if (window.XMLHttpRequest){//If it is not IE, copy it in FLASH
$('buttonBox').innerHTML = 'height="23" quality="high"
pluginspage="http://www.macromedia.com/go/getflashplayer"
type="application/x-shockwave-flash">< ;/embed>';
}

The following are all the JS files:
Copy code The code is as follows:

<script> <br>function $(id){ <br>return document.getElementById(id); <br>} <br>function copy(){ //ie6 <br>var value = $('testInput').value; <br>window.clipboardData.clearData(); <br>window.clipboardData.setData("Text", value); <br>alert( 'Copy successfully! '); <br>} <br>function flashCopy(){//firefox ....... <br>return $('testInput').value; <br>} <br>function flashCopyBack(){ <br>alert('Copy successfully!'); <br>} <br>if("v" != "v"){//If it is not IE, use FLASH to copy <br>$(' buttonBox').innerHTML = '<embed src="111.swf" width="48" height="23" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type ="application/x-shockwave-flash"></embed>'; <br>} <br></script>

The code of the FLASH button is as follows:
Copy code The code is as follows:

on (release) {
import flash.external.ExternalInterface;
var inputText = ExternalInterface.call('flashCopy');
System.setClipboard(inputText);
ExternalInterface.call('flashCopyBack');
//_root.boboText.text = inputText;
}

The principle is to avoid the security restrictions. When clicking the button in FLASH, use the code in FLASH to adjust the JS code in the page. The JS code can get the INPUT and then pass it to FLASH. At this time, there are these values ​​in FLASH. Then, FLASH itself saves these values ​​​​to the clipboard through System.setClipboard; then, he calls the page. flashCopyBack, flashCopyBack only does one thing, which is to prompt that the copy has been successful!
I have tested it in Firefox, Chrome, and IE, and there is no problem. If anyone finds any problem, please tell me, thank you, because I have started using it now!
Please indicate the source for reprinting: Zi Mouse
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn