Show an Alert View in UIWebView

Updated 20 September 2022


This article is on how to show an Alert view in UIWebView.

The weblinks containing the pop-ups or alerts can be handled in WebKit.

UIWebView delegate functions can handle the alert elegantly in the iOS application.

So let’s start learning.

Integrating Alert View in Weblink

Firstly let’s create a web link that contains an alert view.

Go to our favorite website W3School

It’s time to add the code to display the alert on the website.

Add the below code for displaying the alert view on the website.

Now hit run in the editor, and you will see the webpage with a button named “Show Alert”

Now click on the Show Alert button, and you will see a pop-up on the webpage as below.

Show an Alert View in UIWebView

Copy the web link, we have to open this inside our UIWebview in Swift.

Now let’s Show an Alert View in UIWebView.

Integrating Alert View in UIWebView

We will open the copied web link on the previous section inside our UIWebView in Swift.

Create an Xcode project and add UIWebView in your ViewController class as below.

Now add the WebView function runJavaScriptAlertPanelWithMessage that will actually handle the displaying of the alert in our application.

This will pop up an alert view in our application as shown below.

Show an alert View in UIWebView

Now you are done integrating the Alert view in UIWebview.

That’s all for this article.

We hope you liked the article.

Please visit my other blogs here.

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*

Be the first to comment.

Start a Project

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home