Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot call method 'copy' of undefined #1

Closed
bau720123 opened this issue Nov 12, 2013 · 22 comments
Closed

Cannot call method 'copy' of undefined #1

bau720123 opened this issue Nov 12, 2013 · 22 comments

Comments

@bau720123
Copy link

I am using phonegap build 3.1,and very sure that my phonegap.js and clipboard.js are all loaded successfully

but when I use your code and run it...nothing happened
and I use Chrome to debug,it said "Cannot call method 'copy' of undefined"

here is my code

http://www.littlebau.com/copy.html

@gouravkakkar
Copy link
Contributor

From phonegap build 3.1.0 , you dont need to write-

$.getScript("js/plugins/com.verso.cordova.clipboard/www/clipboard.js");

Use the code in the following way -

var text="Sample Text";
cordova.plugins.clipboard.copy(text);

@bau720123
Copy link
Author

when I just use
http://www.littlebau.com/copy.html
but nothing happened too

@gouravkakkar
Copy link
Contributor

Make sure the plugin has been properly configured in your project.You can confirm this by checking in the YourProject/res/xml/config.xml , the plugin should be registered in this way:

<feature name="Clipboard">
        <param name="android-package" value="com.verso.cordova.clipboard.Clipboard" />
   </feature>

Or by running this command from CLI interface:

$ phonegap local plugin list

If properly configured, the plugin should be listed there.

From Phonegap 3.1.0, you dont need to import any specific js files of plugins. Just register them by CLI Interface.

@ctrevisan
Copy link
Contributor

As @gouravkakkar pointed out, it seems that the plugin hasn't been installed properly. You should try reinstalling it.

@bau720123
Copy link
Author

OK
I will try later,really thanks

@bau720123
Copy link
Author

I tried many many times,it still not work by "phonegap build" 3.1

in phonegap build just like that way
https://build.phonegap.com/plugins/67

is it real work by "phonegap build"?

PS,I am very sure that the Clipboard plugin has been install
http://www.littlebau.com/clipboard.jpg

@jprichardson
Copy link

Using Phonegap 3.1 in iOS 7, it works just fine for me.

Example:

cordova.plugins.clipboard.copy('some text');

@bau720123
Copy link
Author

thanks for jprichardson reply
did you use "phonegap build" 3.1 or just phonegap 3.1(Eclipse or xcode) ?

@jprichardson
Copy link

phonegap build ios

@bau720123
Copy link
Author

ok
Could you help me to check out your cordova_plugins.js
There are some code written by...
http://www.littlebau.com/abc.html

is it as same as yours?

@ctrevisan
Copy link
Contributor

Are you building locally or remotely with PhoneGap Build, and for what platform?

@bau720123
Copy link
Author

remotely

Android,4.03,HTC Sensationa XL
iOS,7.0.4,iPad mini

I will try in locally building
If I have any problem then ask your again,tks~

@bau720123
Copy link
Author

I just test the Android 4.1.1 and iOS 7.0.4

this is my "local" index.html code,and I am very sure that my phonegap.js is loaded success
and the plugin is install success too
http://www.littlebau.com/local.gif

<script src="phonegap.js" type="text/javascript"></script>
<script type="text/javascript">
function local1()
{
var text = "Hello World!";
window.plugins.copy(text);
window.plugins.paste(function (text) { alert(text); });
}

function local2()
{
var text = "Hello World!";
cordova.plugins.copy(text);
cordova.plugins.paste(function (text) { alert(text); });
}

function local3()
{
cordova.plugins.copy('Hello World!');
cordova.plugins.paste(function (text) { alert(text); });
}
</script>

<body>
<a onClick="local1();">local1</a></br></br>
<a onClick="local2();">local2</a></br></br>
<a onClick="local3();">local3</a></br></br>
</body>

no mater I click the local1 or local2 or local3,the alert message never appear

@ctrevisan
Copy link
Contributor

You have to change your commands to cordova.plugins.clipboard.copy and cordova.plugins.clipboard.paste.

@bau720123
Copy link
Author

thanks to @ctrevisan
but not work too by phonegap build 3.1....no "alert" message appear
I am not lying,this is the apk file,you can extract the apk file by winzip or winrar to see the index.html
http://www.littlebau.com/clipboard.apk

by the way
my config.xml "android-minSdkVersion" is 11

@ctrevisan
Copy link
Contributor

The sources for the plugin are missing from your project. You should have Clipboard.java under platforms/android/src/com/verso/cordova/clipboard. This might happen if the platform was added (e.g. compiled for using phonegap) before the plugin was added. Try creating a blank project from the CLI, add the plugin, copy your basic example, and compile.

@bau720123
Copy link
Author

I don't know how to use the CLI
I am just only use "phonegap build" and use you plugin by this address
https://build.phonegap.com/plugins/67
anyway...tks~

@bau720123
Copy link
Author

well~
I finally find a way to solve my problem in phonegap build 3.1

is to use...window,not cordova

window.plugins.clipboard.copy(text);
window.plugins.clipboard.paste(function (text) { alert(text); });

@ctrevisan
Copy link
Contributor

Strange... Anyway, I'm glad it solved your problem :-)

@mahavirjain
Copy link

For cordova CLI use cordova.plugins.clipboard.copy and cordova.plugins.clipboard.paste

@kooroshekabir
Copy link

@bau720123 : hi can you give me a link of your example?

@prantikv
Copy link

i am getting the same problem with ionic ngCordova i have opened a new issue here #14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants