CL So
CL So

Reputation: 3759

Can I open webview link in browser without change java code?

In my webview app, some external url will open in same webview, I want these link open in default browser.

I know I can use shouldOverrideUrlLoading to solve this problem, but I don't want change java code because some reason.

Is it possible solve this in HTML or Javascript?

Some people said, I can use this

$(document).on('click', 'a[target="_blank"]', function(ev) {
    var url;
    ev.preventDefault();
    url = $(this).attr('href');
    window.open(url, '_system');
});

But I tried, it does not work.

Upvotes: 2

Views: 1721

Answers (1)

Tie Zhong
Tie Zhong

Reputation: 19

When you say it doesn't work, is it because of window.open() failed to load it into a new window, or the click handler didn't get triggered at all?

  • window.open(url, '_system') will open the url into the same window every time.
  • Try window.open(url, '_blank') to launch a new tab/window every time.

But first of all, make sure your click handler is triggered.

Upvotes: 1

Related Questions