3

How to get scalesPageToFit behaviour for HTML content displayed in a WKWebView without using JavaScript? (disabling JS is a requirement for in our case).

Sorry for not posting any code, but I have no idea how I could achieve this. All solutions I know and all I found are based on JS. Example.

I already add <meta name="viewport" content="width=device-width, initial-scale=1.0"/> to the HTML if it does not exist yet, but at least images are often displayed way too big.

All images are provided to WKWebView by a WKURLSchemeHandler.

shallowThought
  • 19,212
  • 9
  • 65
  • 112

2 Answers2

7

Please put

<meta name="viewport" content="initial-scale=1.0" />

inside your <head> tag.

PPL
  • 6,357
  • 1
  • 11
  • 30
0
extension String {
    mutating func fitContentToScreen() {
        self.add(prefix: "<header><meta name='viewport' content='width=device-width, user-scalable=yes'></header>")
    }
}

You add this header line to html content to fit screen.

Kaan Ozdemir
  • 165
  • 2
  • 9