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.

zmarties
  • 4,809
  • 22
  • 39
Hemant Metalia
  • 29,730
  • 18
  • 72
  • 91
  • [This](http://strongloop.com/strongblog/apples-ios7-native-javascript-bridge/) may help you. This tut discusses communication between objc and js and vice-versa. – jnix Mar 26 '14 at 12:31
  • @jnix can you send link ? – Hemant Metalia Mar 26 '14 at 12:33
  • my above comment includes link. again you can refer Here -http://strongloop.com/strongblog/apples-ios7-native-javascript-bridge/ – jnix Mar 26 '14 at 12:38
  • I have gone through that link but I am not able to identify how to identify click source in delegate method. – Hemant Metalia Mar 26 '14 at 12:55

1 Answers1

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

Community
  • 1
  • 1
jnix
  • 480
  • 3
  • 10
  • yes, but in delegate how can i identify if the register is clicked or login is clicked ? – Hemant Metalia Mar 26 '14 at 13:01
  • check http://example/menu I want to open this page in uiwebview. and open further pages according the method specified on click of each menu – Hemant Metalia Mar 26 '14 at 13:04
  • 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 http://example//login =>login and last part of http://example//register => register hence you can get what you want. – jnix Mar 26 '14 at 13:05
  • 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 ? – Hemant Metalia Mar 26 '14 at 13:07
  • you have to set webview.delgate = youclassobject (youclassobject is class where you want to get notified for that delegate) – jnix Mar 26 '14 at 13:08
  • Most important I checked that URL there are ajax call on clicking controls on that page so [THIS](http://stackoverflow.com/questions/5353278/uiwebviewdelegate-not-monitoring-xmlhttprequest) is more relevent to your solution – jnix Mar 26 '14 at 13:10