Flash interacts with JavaScript

Source: Internet
Author: User

A recent project requires JavaScript to automate the copying of text to the Clipboard, but only ie6.0 support is found when testing.

Baidu Search after found that the original ie7.0, Firefox is not support such operations, and then search for a bit, to find a solution:

Use JavaScript to call Flash to copy text to the Clipboard.

Things to note in HTML code:

In the object tag, insert id= "Fcopy"
In the Embed tab, insert Name= "fcopy" and swliveconnect= "true" to ensure that the id attribute is not used!

Flash Code:

// Import Externalinterface class Import Flash.external.ExternalInterface; function Copy (str) {system.setclipboard (str); GetURL ("Javascript:alert (' copied, use Ctrl + V paste out ')");


Allow Flalert () in JS to call Showalert () in Flash
Externalinterface.addcallback ("Copy", null,copy);

HTML code:

<ObjectClassID= "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"codebase= "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0"ID= "Fcopy"width= "1"Height= "1"><paramname= "movie"value= "flash/clipboard.swf"><paramname= "Quality"value= "High"><paramname= "Swliveconnect"value= "true"><Embedsrc= "flash/clipboard.swf"width= "1"Height= "1"Quality= "High"pluginspage= "Http://www.macromedia.com/go/getflashplayer"type= "Application/x-shockwave-flash"name= "Fcopy"Swliveconnect= "true"></Embed></Object>

JS Code:

varBrowser =NewObject ();functionGetbrowser () {varb =navigator.userAgent.toLowerCase (); browser={safari:/webkit/. Test (b), Opera:/opera/. Test (b), IE6:/msie 6/.test (b) &&!/opera/. Test (b), IE7:/msie 7/.test (b) &&!/opera/. Test (b), MSIE:/msie/.test (b) &&!/opera/. Test (b), Mozilla:/mozilla/.test (b) &&!/(Compatible|webkit)/. Test (b)};} Getbrowser ();//Copy to clipboardfunctioncopycode (field) {Field.select ();vartext=Field.value;if(browser.ie6) {Window.clipboardData.setData (' Text ', Text) alert (' Copied, please use CTRL + V to paste it out ') ;}Else{flashCopy (text);//copy using Flash mode}}//call the method in Flash, "Fcopy" is the ID of the SWF in the HTML pagefunctionflashCopy (text) {Thismovie ("Fcopy"). copy (text);}//build JS and flash interoperability EnvironmentfunctionThismovie (moviename) {if(Navigator.appName.indexOf ("Microsoft")! =-1) {returnWindow[moviename]}Else{returnDocument[moviename]}}

Flash interacts with JavaScript

Related Article

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.