0

Hello I am working on application in which i am opening a menu in a webview in ios.

The menu is an html page. say menu have two options

  1. Register
  2. Login

I have following pages already developed.

1. http://example//menu
2. http://example//register
3. http://example//login

I am able to open menu page in a webview. now what i want to do is create a method in objective c like openpage(url) this function should open the url in webview.

The html pages works fine in Android, i want to get it working in ios.

the register onclick method is written as follow:

onclick="window.jsInterface.openPage('http://example//register'); return false;">

so I will require to create a interface named jsinterface and a method openpage into it. but I am not clear how to do it.

one more thing I want to know howdelegate method will identify the click of register and menu. that is if register is clicked then I need to open http://example//register page and if login is clicked then i want to open http://example//login.

4
  • This may help you. This tut discusses communication between objc and js and vice-versa. Commented Mar 26, 2014 at 12:31
  • @jnix can you send link ? Commented Mar 26, 2014 at 12:33
  • my above comment includes link. again you can refer Here -strongloop.com/strongblog/apples-ios7-native-javascript-bridge Commented Mar 26, 2014 at 12:38
  • I have gone through that link but I am not able to identify how to identify click source in delegate method. Commented Mar 26, 2014 at 12:55

1 Answer 1

1

you can use webView:shouldStartLoadWithRequest:navigationType: delegate method for UIWebView

if you added delegate to UIWebView then above method gets called every time you click on any link in HTML page in webView . for more info. refer THIS

Sign up to request clarification or add additional context in comments.

6 Comments

yes, but in delegate how can i identify if the register is clicked or login is clicked ?
check example/menu I want to open this page in uiwebview. and open further pages according the method specified on click of each menu
you can by simply parsing the link received in NSURlrequest in webView:shouldStartLoadWithRequest:navigationType: method you can get last part after // i.e. last part of example//login =>login and last part of example//register => register hence you can get what you want.
I am trying this but when clicking on any menu the delegate method is not getting executed. do i need any other configuration for that ?
you have to set webview.delgate = youclassobject (youclassobject is class where you want to get notified for that delegate)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.