Copy the input content of the JS code _ support all browsers, fixed Firefox3.5 above problems _javascript skills

Source: Internet
Author: User

But IE6 two lines of JS code can be, IE7 above also similar, just come out a security hint more disgusting, the user if see, must have suspicion;
Again but is Firefox, Chrome and so on do not let you copy;
Remember before the Internet has this code, looked for a moment, found that all can not be in firefox3.5 above version should, finally found a, the code is quite quite complex, not too dare to use.
Finally, there is no way to suppress, check the data, since has written a:
A few points of the main understanding:
1, Firefox these browsers, for security reasons, directly is not to copy;
2, in Flash, you can use System.setclipboard (), the content to throw on the Clipboard, and then let Flash work under Firefox;
3, after the Flash Player 10.0, but also for security considerations, System.setclipboard content must be in the flash inside;
4, with Externalinterface can and JS communication;
5, Externalinterface in the Flash8 must be quoted in order to be able;
Default HTML code:
Copy Code code as follows:

<input type= "text" id= "Testinput" name= "Testinput" value= "4234324234"/>
<div id= "Buttonbox" >
<button onclick= "Copy (' Testinput ')" >copy</button>
</div>

Therefore, the design, first make the first judgment, if it is IE, the default code, so that the most no problem, if not, with a flash to the default button coverage;
Copy Code code as follows:

if (window. XMLHttpRequest) {////If not IE, copy in flash mode
$ (' Buttonbox '). InnerHTML = ' <embed src= "flashcopy.swf" width= "48"
height= "quality=" "High"
Pluginspage= "Http://www.macromedia.com/go/getflashplayer"
Type= "Application/x-shockwave-flash" ></embed>;
}

Here are all the JS files:
Copy Code code as follows:

<script>
function $ (ID) {
return document.getElementById (ID);
}
function copy () {//ie6
var value = $ (' testinput '). Value;
Window.clipboardData.clearData ();
Window.clipboardData.setData ("Text", value);
Alert (' Copy successful! ');
}
function FlashCopy () {//firefox .....
return $ (' Testinput '). Value;
}
function Flashcopyback () {
Alert (' Copy successful! ');
}
if ("V"!= "V") {//If it is not ie, copy it in Flash
$ (' Buttonbox '). InnerHTML = ' <embed src= "111.swf" width= "" height= "" quality= "High" pluginspage= "http:// Www.macromedia.com/go/getflashplayer "type=" Application/x-shockwave-flash "></embed>";
}
</script>

The code for the Flash button is as follows:
Copy Code code as follows:

On (release) {
Import Flash.external.ExternalInterface;
var inputtext = externalinterface.call (' flashCopy ');
System.setclipboard (Inputtext);
Externalinterface.call (' Flashcopyback ');
_root.bobotext.text = Inputtext;
}

Principle, is to avoid the security restrictions, in the Flash button, through the Flash code to adjust the page in the JS code, JS code can get input value, and then to Flash, at this time, Flash has these values, and then, Flash has been system.setclipboard to save these values to the Clipboard, and then he went to the page to call the Flashcopyback,flashcopyback only one thing, is that the hint has been replicated successfully!
I have been in Firefox, Chrome, ie have been tested, no problem, if anyone found that there is a problem, please tell me, thank you, because I have now started to use!
Reprint, please indicate the source: child Mouse

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.