Copy button in a WebView doesn't work - why?

Multi tool use
Multi tool use












0














In my app I have a webView, where I'm displaying web site, when I'm trying to click on the copy button, it doesn't copy anything. How is possible to fix that?



Here what I have tried so far, but it didn't help:



webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setDatabaseEnabled(true);
webView.getSettings().setMinimumFontSize(1);
webView.getSettings().setMinimumLogicalFontSize(1);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setAllowContentAccess(true);


I'm checking Logcat and see this error, while clicking on the copy button in the website: "




Uncaught (in promise) undefined




"However, this button works okay in the browser, but doesn't work in WebView.










share|improve this question
























  • What are you trying to copy? the html code?
    – Nero
    Dec 27 at 13:17










  • @Nero text inside the website
    – Lucky_girl
    Dec 27 at 13:20










  • I've found the approach in order to tackle this... basically, you'll need to catch the event when the copy button is clicked. Once you catch that event, the text will be copied into the ClipBoard and you can extract the test from the ClipBoard. I've been trying to code an example in order to catch a button click event in the WebView but haven't had any success yet.
    – Nero
    yesterday










  • @Nero for click event possible to use this solution stackoverflow.com/questions/5116909/… What was your approach regarding click board?
    – Lucky_girl
    yesterday
















0














In my app I have a webView, where I'm displaying web site, when I'm trying to click on the copy button, it doesn't copy anything. How is possible to fix that?



Here what I have tried so far, but it didn't help:



webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setDatabaseEnabled(true);
webView.getSettings().setMinimumFontSize(1);
webView.getSettings().setMinimumLogicalFontSize(1);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setAllowContentAccess(true);


I'm checking Logcat and see this error, while clicking on the copy button in the website: "




Uncaught (in promise) undefined




"However, this button works okay in the browser, but doesn't work in WebView.










share|improve this question
























  • What are you trying to copy? the html code?
    – Nero
    Dec 27 at 13:17










  • @Nero text inside the website
    – Lucky_girl
    Dec 27 at 13:20










  • I've found the approach in order to tackle this... basically, you'll need to catch the event when the copy button is clicked. Once you catch that event, the text will be copied into the ClipBoard and you can extract the test from the ClipBoard. I've been trying to code an example in order to catch a button click event in the WebView but haven't had any success yet.
    – Nero
    yesterday










  • @Nero for click event possible to use this solution stackoverflow.com/questions/5116909/… What was your approach regarding click board?
    – Lucky_girl
    yesterday














0












0








0







In my app I have a webView, where I'm displaying web site, when I'm trying to click on the copy button, it doesn't copy anything. How is possible to fix that?



Here what I have tried so far, but it didn't help:



webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setDatabaseEnabled(true);
webView.getSettings().setMinimumFontSize(1);
webView.getSettings().setMinimumLogicalFontSize(1);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setAllowContentAccess(true);


I'm checking Logcat and see this error, while clicking on the copy button in the website: "




Uncaught (in promise) undefined




"However, this button works okay in the browser, but doesn't work in WebView.










share|improve this question















In my app I have a webView, where I'm displaying web site, when I'm trying to click on the copy button, it doesn't copy anything. How is possible to fix that?



Here what I have tried so far, but it didn't help:



webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setDatabaseEnabled(true);
webView.getSettings().setMinimumFontSize(1);
webView.getSettings().setMinimumLogicalFontSize(1);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setAllowContentAccess(true);


I'm checking Logcat and see this error, while clicking on the copy button in the website: "




Uncaught (in promise) undefined




"However, this button works okay in the browser, but doesn't work in WebView.







android webview






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday

























asked Dec 27 at 13:05









Lucky_girl

73411025




73411025












  • What are you trying to copy? the html code?
    – Nero
    Dec 27 at 13:17










  • @Nero text inside the website
    – Lucky_girl
    Dec 27 at 13:20










  • I've found the approach in order to tackle this... basically, you'll need to catch the event when the copy button is clicked. Once you catch that event, the text will be copied into the ClipBoard and you can extract the test from the ClipBoard. I've been trying to code an example in order to catch a button click event in the WebView but haven't had any success yet.
    – Nero
    yesterday










  • @Nero for click event possible to use this solution stackoverflow.com/questions/5116909/… What was your approach regarding click board?
    – Lucky_girl
    yesterday


















  • What are you trying to copy? the html code?
    – Nero
    Dec 27 at 13:17










  • @Nero text inside the website
    – Lucky_girl
    Dec 27 at 13:20










  • I've found the approach in order to tackle this... basically, you'll need to catch the event when the copy button is clicked. Once you catch that event, the text will be copied into the ClipBoard and you can extract the test from the ClipBoard. I've been trying to code an example in order to catch a button click event in the WebView but haven't had any success yet.
    – Nero
    yesterday










  • @Nero for click event possible to use this solution stackoverflow.com/questions/5116909/… What was your approach regarding click board?
    – Lucky_girl
    yesterday
















What are you trying to copy? the html code?
– Nero
Dec 27 at 13:17




What are you trying to copy? the html code?
– Nero
Dec 27 at 13:17












@Nero text inside the website
– Lucky_girl
Dec 27 at 13:20




@Nero text inside the website
– Lucky_girl
Dec 27 at 13:20












I've found the approach in order to tackle this... basically, you'll need to catch the event when the copy button is clicked. Once you catch that event, the text will be copied into the ClipBoard and you can extract the test from the ClipBoard. I've been trying to code an example in order to catch a button click event in the WebView but haven't had any success yet.
– Nero
yesterday




I've found the approach in order to tackle this... basically, you'll need to catch the event when the copy button is clicked. Once you catch that event, the text will be copied into the ClipBoard and you can extract the test from the ClipBoard. I've been trying to code an example in order to catch a button click event in the WebView but haven't had any success yet.
– Nero
yesterday












@Nero for click event possible to use this solution stackoverflow.com/questions/5116909/… What was your approach regarding click board?
– Lucky_girl
yesterday




@Nero for click event possible to use this solution stackoverflow.com/questions/5116909/… What was your approach regarding click board?
– Lucky_girl
yesterday












1 Answer
1






active

oldest

votes


















0














Based on the comment you've wrote, you've mentioned that you want to extract the text from the website. You'll need to identify which text you want exactly and locate it within the HTML code.


The following solution will allow you to extract the HTML code of the given website but you'll have to narrow it down to exactly which text you want to extract further and in which attribute it's located in i.e. class/id



webView.evaluateJavascript(
"(function() { return ('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>'); })();",
new ValueCallback<String>() {
@Override
public void onReceiveValue(String html) {
Log.d("HTML", html);
// This should log the html code within the log cat
}
});


-Would like to credit Balaji M for the answer under html content in webview as it also contributes this question.-



~~I would like to keep my previous answer in place in case you do decide to change your approach on this question~~



As you've already located the answer to the event listener where you will be able to detect when the copy button is triggered within the webView, the only part of functionality which is missing now is the paste from ClipBoard.

Should put the following code within the onCreate method:



// Gets a handle to the clipboard service.
ClipboardManager clipboardManager = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);


Now it's time to copy the data from the clipboard into our String variable or any other variable type.



// Get clip data from clipboard.
ClipData clipData = clipboardManager.getPrimaryClip();
// Get item count.
int itemCount = clipData.getItemCount();
if(itemCount > 0){
// Get source text.
Item item = clipData.getItemAt(0);
String copiedData = item.getText().toString();
//For testing purpose, display toast containig your copied data
Toast.makeText(getActivity(), copiedData , Toast.LENGTH_LONG).show();
}





share|improve this answer























  • I'm not exactly sure that that's exactly what I need, there s a copy button in the website, and when I'm clicking on it in the browser it works, bur it doesn't work in the WebView, so I think, that something is breaking JavaScript from the executing correctly in the WebView.
    – Lucky_girl
    yesterday










  • @Lucky_girl you see, I didn't know that there was a button within the webview which will copy the text automatically to the clipboard. I'll modify my answer to accommodate the requested functionality (this piece of information should've been in the initial question).
    – Nero
    yesterday










  • @Lucky_girl please review the answer again for the requested functionality.
    – Nero
    yesterday











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53945593%2fcopy-button-in-a-webview-doesnt-work-why%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Based on the comment you've wrote, you've mentioned that you want to extract the text from the website. You'll need to identify which text you want exactly and locate it within the HTML code.


The following solution will allow you to extract the HTML code of the given website but you'll have to narrow it down to exactly which text you want to extract further and in which attribute it's located in i.e. class/id



webView.evaluateJavascript(
"(function() { return ('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>'); })();",
new ValueCallback<String>() {
@Override
public void onReceiveValue(String html) {
Log.d("HTML", html);
// This should log the html code within the log cat
}
});


-Would like to credit Balaji M for the answer under html content in webview as it also contributes this question.-



~~I would like to keep my previous answer in place in case you do decide to change your approach on this question~~



As you've already located the answer to the event listener where you will be able to detect when the copy button is triggered within the webView, the only part of functionality which is missing now is the paste from ClipBoard.

Should put the following code within the onCreate method:



// Gets a handle to the clipboard service.
ClipboardManager clipboardManager = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);


Now it's time to copy the data from the clipboard into our String variable or any other variable type.



// Get clip data from clipboard.
ClipData clipData = clipboardManager.getPrimaryClip();
// Get item count.
int itemCount = clipData.getItemCount();
if(itemCount > 0){
// Get source text.
Item item = clipData.getItemAt(0);
String copiedData = item.getText().toString();
//For testing purpose, display toast containig your copied data
Toast.makeText(getActivity(), copiedData , Toast.LENGTH_LONG).show();
}





share|improve this answer























  • I'm not exactly sure that that's exactly what I need, there s a copy button in the website, and when I'm clicking on it in the browser it works, bur it doesn't work in the WebView, so I think, that something is breaking JavaScript from the executing correctly in the WebView.
    – Lucky_girl
    yesterday










  • @Lucky_girl you see, I didn't know that there was a button within the webview which will copy the text automatically to the clipboard. I'll modify my answer to accommodate the requested functionality (this piece of information should've been in the initial question).
    – Nero
    yesterday










  • @Lucky_girl please review the answer again for the requested functionality.
    – Nero
    yesterday
















0














Based on the comment you've wrote, you've mentioned that you want to extract the text from the website. You'll need to identify which text you want exactly and locate it within the HTML code.


The following solution will allow you to extract the HTML code of the given website but you'll have to narrow it down to exactly which text you want to extract further and in which attribute it's located in i.e. class/id



webView.evaluateJavascript(
"(function() { return ('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>'); })();",
new ValueCallback<String>() {
@Override
public void onReceiveValue(String html) {
Log.d("HTML", html);
// This should log the html code within the log cat
}
});


-Would like to credit Balaji M for the answer under html content in webview as it also contributes this question.-



~~I would like to keep my previous answer in place in case you do decide to change your approach on this question~~



As you've already located the answer to the event listener where you will be able to detect when the copy button is triggered within the webView, the only part of functionality which is missing now is the paste from ClipBoard.

Should put the following code within the onCreate method:



// Gets a handle to the clipboard service.
ClipboardManager clipboardManager = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);


Now it's time to copy the data from the clipboard into our String variable or any other variable type.



// Get clip data from clipboard.
ClipData clipData = clipboardManager.getPrimaryClip();
// Get item count.
int itemCount = clipData.getItemCount();
if(itemCount > 0){
// Get source text.
Item item = clipData.getItemAt(0);
String copiedData = item.getText().toString();
//For testing purpose, display toast containig your copied data
Toast.makeText(getActivity(), copiedData , Toast.LENGTH_LONG).show();
}





share|improve this answer























  • I'm not exactly sure that that's exactly what I need, there s a copy button in the website, and when I'm clicking on it in the browser it works, bur it doesn't work in the WebView, so I think, that something is breaking JavaScript from the executing correctly in the WebView.
    – Lucky_girl
    yesterday










  • @Lucky_girl you see, I didn't know that there was a button within the webview which will copy the text automatically to the clipboard. I'll modify my answer to accommodate the requested functionality (this piece of information should've been in the initial question).
    – Nero
    yesterday










  • @Lucky_girl please review the answer again for the requested functionality.
    – Nero
    yesterday














0












0








0






Based on the comment you've wrote, you've mentioned that you want to extract the text from the website. You'll need to identify which text you want exactly and locate it within the HTML code.


The following solution will allow you to extract the HTML code of the given website but you'll have to narrow it down to exactly which text you want to extract further and in which attribute it's located in i.e. class/id



webView.evaluateJavascript(
"(function() { return ('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>'); })();",
new ValueCallback<String>() {
@Override
public void onReceiveValue(String html) {
Log.d("HTML", html);
// This should log the html code within the log cat
}
});


-Would like to credit Balaji M for the answer under html content in webview as it also contributes this question.-



~~I would like to keep my previous answer in place in case you do decide to change your approach on this question~~



As you've already located the answer to the event listener where you will be able to detect when the copy button is triggered within the webView, the only part of functionality which is missing now is the paste from ClipBoard.

Should put the following code within the onCreate method:



// Gets a handle to the clipboard service.
ClipboardManager clipboardManager = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);


Now it's time to copy the data from the clipboard into our String variable or any other variable type.



// Get clip data from clipboard.
ClipData clipData = clipboardManager.getPrimaryClip();
// Get item count.
int itemCount = clipData.getItemCount();
if(itemCount > 0){
// Get source text.
Item item = clipData.getItemAt(0);
String copiedData = item.getText().toString();
//For testing purpose, display toast containig your copied data
Toast.makeText(getActivity(), copiedData , Toast.LENGTH_LONG).show();
}





share|improve this answer














Based on the comment you've wrote, you've mentioned that you want to extract the text from the website. You'll need to identify which text you want exactly and locate it within the HTML code.


The following solution will allow you to extract the HTML code of the given website but you'll have to narrow it down to exactly which text you want to extract further and in which attribute it's located in i.e. class/id



webView.evaluateJavascript(
"(function() { return ('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>'); })();",
new ValueCallback<String>() {
@Override
public void onReceiveValue(String html) {
Log.d("HTML", html);
// This should log the html code within the log cat
}
});


-Would like to credit Balaji M for the answer under html content in webview as it also contributes this question.-



~~I would like to keep my previous answer in place in case you do decide to change your approach on this question~~



As you've already located the answer to the event listener where you will be able to detect when the copy button is triggered within the webView, the only part of functionality which is missing now is the paste from ClipBoard.

Should put the following code within the onCreate method:



// Gets a handle to the clipboard service.
ClipboardManager clipboardManager = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);


Now it's time to copy the data from the clipboard into our String variable or any other variable type.



// Get clip data from clipboard.
ClipData clipData = clipboardManager.getPrimaryClip();
// Get item count.
int itemCount = clipData.getItemCount();
if(itemCount > 0){
// Get source text.
Item item = clipData.getItemAt(0);
String copiedData = item.getText().toString();
//For testing purpose, display toast containig your copied data
Toast.makeText(getActivity(), copiedData , Toast.LENGTH_LONG).show();
}






share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday

























answered Dec 27 at 13:48









Nero

5891316




5891316












  • I'm not exactly sure that that's exactly what I need, there s a copy button in the website, and when I'm clicking on it in the browser it works, bur it doesn't work in the WebView, so I think, that something is breaking JavaScript from the executing correctly in the WebView.
    – Lucky_girl
    yesterday










  • @Lucky_girl you see, I didn't know that there was a button within the webview which will copy the text automatically to the clipboard. I'll modify my answer to accommodate the requested functionality (this piece of information should've been in the initial question).
    – Nero
    yesterday










  • @Lucky_girl please review the answer again for the requested functionality.
    – Nero
    yesterday


















  • I'm not exactly sure that that's exactly what I need, there s a copy button in the website, and when I'm clicking on it in the browser it works, bur it doesn't work in the WebView, so I think, that something is breaking JavaScript from the executing correctly in the WebView.
    – Lucky_girl
    yesterday










  • @Lucky_girl you see, I didn't know that there was a button within the webview which will copy the text automatically to the clipboard. I'll modify my answer to accommodate the requested functionality (this piece of information should've been in the initial question).
    – Nero
    yesterday










  • @Lucky_girl please review the answer again for the requested functionality.
    – Nero
    yesterday
















I'm not exactly sure that that's exactly what I need, there s a copy button in the website, and when I'm clicking on it in the browser it works, bur it doesn't work in the WebView, so I think, that something is breaking JavaScript from the executing correctly in the WebView.
– Lucky_girl
yesterday




I'm not exactly sure that that's exactly what I need, there s a copy button in the website, and when I'm clicking on it in the browser it works, bur it doesn't work in the WebView, so I think, that something is breaking JavaScript from the executing correctly in the WebView.
– Lucky_girl
yesterday












@Lucky_girl you see, I didn't know that there was a button within the webview which will copy the text automatically to the clipboard. I'll modify my answer to accommodate the requested functionality (this piece of information should've been in the initial question).
– Nero
yesterday




@Lucky_girl you see, I didn't know that there was a button within the webview which will copy the text automatically to the clipboard. I'll modify my answer to accommodate the requested functionality (this piece of information should've been in the initial question).
– Nero
yesterday












@Lucky_girl please review the answer again for the requested functionality.
– Nero
yesterday




@Lucky_girl please review the answer again for the requested functionality.
– Nero
yesterday


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53945593%2fcopy-button-in-a-webview-doesnt-work-why%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







RAFNAQK hkgh,9sHm2Nmo2v767 OS8BoIsB,Kr
wVKEN6Bz8K9P b5i97b mzGoyqjeiRm7NNhsR5Bz,ASmJ mhLko 8vi4GhAkmQ8gQbXbbLm0pr,OFkwA8Gt

Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas