Disable copy and paste in IOS uiwebview

Source: Internet
Author: User

As required by the project, you must disable the copy paste menu option in input when loading HTML using uiwebview.

Modify HTML page

Method 1:

Function onload ()

{

Document.doc umentelement. style. webkittouchcallout = "NONE"; // The menu is disabled.

Document.doc umentelement. style. webkituserselect = "NONE"; // do not select

}

Then add onload to the body.

<Body onload = "onLoad ()"/>

In actual tests, the copy and paste functions are not allowed in input.

HTML page content. The copy function is disabled.

Method 2:

<Style type = "text/CSS">

*{

-WebKit-user-select: none;/* disable selection/copy of uiwebview */

}

</Style>

In actual tests, the copy and paste function is disabled, but the keyboard input cannot be displayed in the webview input.



Modify IOS code:

Method 1:

-(Void) webviewdidfinishload :( uiwebview *) webview {

// Disable User Selection

[Webview stringbyevaluatingjavascriptfromstring: @ "document.doc umentelement. style. webkituserselect = 'none';"];

// Disable callout

[Webview stringbyevaluatingjavascriptfromstring: @ "document.doc umentelement. style. webkittouchcallout = 'none';"];

}

In the actual test, the copy and paste functions are not allowed in the input.

HTML page content. The copy function is disabled.

Method 2:

Obtain the uimenucontroller and forcibly hide the view of the menu item,

The actual test is effective and cannot be submitted to the app store.

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.