On Click of anchor (a) open a url in inappbrowser and show loading

5:34 PM

I've a write some functions for this :



document.onclick = function(e) {
e = e || window.event;
var element = e.target || e.srcElement;

if (element.tagName == 'A' && ((element.href.indexOf('http://') >= || element.href.indexOf('https://') >= 0)) && element.href.indexOf('//localhost:') < 0 ) {
e.preventDefault();
var ref = window.open(element.href, "_blank", "location=yes");;
ref.addEventListener('loadstart', inAppBrowserbLoadStart);
ref.addEventListener('loadstop', inAppBrowserbLoadStop);
ref.addEventListener('loaderror', inAppBrowserbLoadError);
ref.addEventListener('exit', inAppBrowserbClose);
return false;
}
}

function inAppBrowserbLoadStart(event) {
   navigator.notification.activityStart("Please Wait", "It'll only take a moment...");
}

function inAppBrowserbLoadStop(event) {
   navigator.notification.activityStop();
}

function inAppBrowserbLoadError(event) {
   navigator.notification.activityStop();
}

function inAppBrowserbClose(event) {
   navigator.notification.activityStop();
   ref.removeEventListener('loadstart', inAppBrowserbLoadStart);
   ref.removeEventListener('loadstop', inAppBrowserbLoadStop);
   ref.removeEventListener('loaderror', inAppBrowserbLoadError);
   ref.removeEventListener('exit', inAppBrowserbClose);

}

You Might Also Like

0 comments