Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8938845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:43:28+00:00 2026-06-15T10:43:28+00:00

I am loading a HTML file file from server inside UIWebView. In HTML file,

  • 0

I am loading a HTML file file from server inside UIWebView. In HTML file, we have external links to open and a Javascript function is written to handle that events.I want to open that hyperlinks inside a seperate new webview within the app.

Is there any way that server side javascript method notify to objective-C or any callback function which will call in objective-C and then i can do someting in my code? i have seen the example of WEBViewJavaScriptBridge to communicate between javascript and objective C. but they are using the local HTML file to load and communicate.Bt my HTML file is on server side.It would be great if anyone can help on this.

I am puuting a sample HTML file here. We have two hypelinks “Open” and “Close” on taping on open button a function is called that show alert. so instead of alert i want to pass the retuen callback to objective-C code.

Here it is:-

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width = device-width, initial-scale = 1.0, maximum-scale = 1.0, minimum-scale = 1.0, user-scalable=no"/>
<meta name="HandheldFriendly" content="True"/>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<title>Test HTML</title>
<script type="text/javascript">

function open(url, offset){
alert("Open Webview with url:"+ url + " & Offset: " + offset);
}

function close(url, offset){
alert("close webview");
}

</script>
</head>
<body>
<a href="javascript:open('http://www.tcm.com', '55')">Open</a><br>
<a href="javascript:close()">Close</a>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:43:28+00:00Added an answer on June 15, 2026 at 10:43 am

    I used webviewjavascriptbridge to communicate javascript and objective C code.

    In this example code, note the global variable of bridge.

    <!doctype html>
    <html><head>
    <style type='text/css'>
        html { font-family:Helvetica; color:#222; }
        h1 { color:steelblue; font-size:24px; margin-top:24px; }
        button { margin:0 3px 10px; font-size:12px; }
        .logLine { border-bottom:1px solid #ccc; padding:4px 2px; font-family:courier; font-size:11px; }
    </style>
    </head><body>
    <h1>WebViewJavascriptBridge Demo</h1>
    <script>
    window.onerror = function(err) {
        alert('window.onerror: ' + err)
    }
    var bridge;
    document.addEventListener('WebViewJavascriptBridgeReady', onBridgeReady, false)
    function onBridgeReady(event){
        alert("Onbridge ready call");
    
        bridge = event.bridge
        var uniqueId = 1
        function log(message, data) {
            var log = document.getElementById('log')
            var el = document.createElement('div')
            el.className = 'logLine'
            el.innerHTML = uniqueId++ + '. ' + message + (data ? ': ' + JSON.stringify(data) : '')
            if (log.children.length) { log.insertBefore(el, log.children[0]) }
            else { log.appendChild(el) }
        }
        bridge.init(function(message) {
            log('JS got a message', message)
        })
    
        bridge.registerHandler('open', function(data, response) {
                               log('JS handler testJavascriptHandler was called', data)
                               response.respondWith({ 'Javascript Says':'open open open!' })
                               })
    
    
    
        bridge.registerHandler('testJavascriptHandler', function(data, response) {
            log('JS handler testJavascriptHandler was called', data)
            response.respondWith({ 'Javascript Says':'Right back atcha!' })
        })
    
        var button = document.getElementById('buttons').appendChild(document.createElement('button'))
        button.innerHTML = 'Send message to ObjC'
        button.ontouchstart = function(e) {
            e.preventDefault()
            bridge.send('Hello from JS button')
        }
    
        document.body.appendChild(document.createElement('br'))
    
        var callbackButton = document.getElementById('buttons').appendChild(document.createElement('button'))
        callbackButton.innerHTML = 'Fire testObjcCallback'
        callbackButton.ontouchstart = function(e) {
            e.preventDefault()
            log("Calling handler testObjcCallback")
            bridge.callHandler('testObjcCallback', {'foo': 'bar'}, function(response) {
                log('Got response from testObjcCallback', response)
            })
        }
    
    }
    
    
    
    function open(url, offset,e)
    {
        alert(bridge);
    
        //alert("Open Webview with url:Yes Got it");
    
    
    
       //  alert(document.getElementById(offset).href);
        //  var bridge = event.bridge;
       // alert(bridge);
    
        window.location = url+'?offset='+offset//'myapp:myaction:url:offset'
    
        //requestFromObjc("buttonColor&someParam=1");
    }
    
    
    function close()
    {
            alert("Open Webview with url:"+ url + " & Offset: " + offset);
    }
    
    function requestFromObjc(functionName, objcResult, callback)
    {
        if (!objcResult)
        {
            window.location = 'myapp:myaction:param1:param2'
           // window.location = "myapp://objcRequest?function=" + functionName + "&callback=" + arguments.callee.name + "&callbackFunc=" + arguments.callee.caller.name;
        }
        else
        {
            window[callback](objcResult);
        }
    }
    
    </script>
    <div id='buttons'></div> <div id='log'></div>
    
    <body>
        <a id="55" href="javascript:open('http://www.tcm.com', '55',this)">Open</a><br>
        <a href="javascript:close()">Close</a>
    </body>
    
    </body></html>
    

    Reference: https://github.com/marcuswestin/WebViewJavascriptBridge

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that is loading html from a remote server in a
When loading a CSS/JS file from CDN or any external server, it is possible
I am loading a HTML from an external server. The HTML markup has UTF-8
I am loading html into a UIWebView from iOS local file system. That HTML
Hi i am loading local html file after handling some javascript alerts on webchromeclient,
I'm using jQuery version 1.7.1 from Google CDN and have the following code: $(menuInstance).delay(2000).removeClass('loading').html(ul);
I am loading a simple txt file from the same server as the current
I'm loading an HTML file from the SD card with android's WebView.loadUrl() method. this
On the first page I have this function: <script> function update() { $(#notice_div).html('Loading..'); $.ajax({
I am having difficulty in loading a html file from my project assets folder

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.