0

So I've created an app that would open an HTML page with some text and links on it. But if I click on a link I the page that would open after will not scale (obviously).

I know that I can scale the WebView in my first ViewController but in that case it will be hard to read my initial HTML page.

I've tried sevral methods:

  1. scale my webView on link clicked:

    if navigationType == UIWebViewNavigationType.LinkClicked {
    
        UIApplication.sharedApplication().openURL(request.URL!)
        myWebView.frame = UIScreen.mainScreen().bounds
        myWebView.center = self.view.center
        myWebView.scalesPageToFit = true
    }
    return true
    

Or like that:

func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {

    switch navigationType {
    case .LinkClicked:
        // Open links in Safari

        UIApplication.sharedApplication().openURL(request.URL!)
        myWebView.scalesPageToFit = true
        return false
    default:
        // Handle other navigation types...
        return true
    }
}

But to no succsess.

After that I've tried to set up a segue to my second ViewController in case link is clicked but the result was still the same.

func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
    if navigationType == UIWebViewNavigationType.LinkClicked {

        let about = self.storyboard?.instantiateViewControllerWithIdentifier("openlink") as! dossierLink
        self.navigationController?.pushViewController(about, animated: true)
    }
    return true
}

Can someone help me out on that one? Thank you!

1 Answers1

0

My recommendtion would be to only load the content of next html page or url

webView.loadDataWithBaseURL(null,urlcontent, "UTF-8", null)

There are many ways to convert url to string content like Android Read contents of a URL (content missing after in result)

Community
  • 1
  • 1
Ashish Rawat
  • 5,541
  • 1
  • 20
  • 17