Last active
May 5, 2023 08:07
-
-
Save ham118/a9eb7f0178c688638708cde56c2f4699 to your computer and use it in GitHub Desktop.
EvaluatingJavaScript : This is gist to change font size and avoid text copy functionality from entire html in UIWebView | Swift 5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This is code to change font size and avoid text copy functionality from entire html in UIWebView | |
//"textSize" : this is integer variable which you want to set font size | |
func webViewDidFinishLoad(_ webView: UIWebView) { | |
if (webView.stringByEvaluatingJavaScript(from: "document.readyState") == "complete") { | |
//Avoid to detect touch gesture for disable user selection | |
webView.stringByEvaluatingJavaScript(from: "document.documentElement.style.webkitUserSelect='none';") | |
webView.stringByEvaluatingJavaScript(from: "document.documentElement.style.webkitTouchCallout='none';") | |
//Set font size | |
let jsString = "document.getElementsByTagName('body')[0].style.fontSize='\(textSize)px'" | |
webView.stringByEvaluatingJavaScript(from: jsString) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment