Search code examples
ioswkwebviewaddsubview

ios - Adding subview to WKWebView below JS Dialog


When adding subview, something like [self.webView.scrollView addSubview:test]; everything works fine.

Problem is javascript alert and it's dimmed screen, because alert is below my newly added view. JS alerts and dialogs should be always on top.

Any ideas?


Solution

  • Javascript alerts from the web view are part of that web view and not separate UIViews.

    If you want something to appear above the main web content and below the javascript alert (which is also web content), then it will need to be web content itself.

    One way to do this would be to make it another javascript-generated object, not UIView.

    Alternatively, you could have a second web view that only displays javascript alerts, and have your UIView appear below your new (second) web view, but then you'd have to manage the relationship between the two web views.