How to prevent Android from Opening New Window for target=_blank links?

You must Login before you can answer or comment on any questions.

I prefer that my Android app work the same way that iOS does, but directing all links to the same webview.

I tried to use some JSEval to remove them, but that's pretty buggy. I'm in the 2.1.2 sdk.

1 Answer

i think you need to write some code to modify the dom of the webview URLs. Can you post some code here so we can provide some information

— answered 9 months ago by Aaron Saunders
answer permalink
3 Comments
  • I tried the following to modify the dom as you suggested, but it hangs this solution causes any other javascript on the page to crash.

    webview.addEventListener('load',function()
    {
     var content = webview.evalJS("document.body.innerHTML = document.body.innerHTML.replace(/target=\"_blank\"/gi, '');");
    });

    — commented 9 months ago by Francis Meetze

  • you should be able to modify the code from this answer to get the result you desire

    https://developer.appcelerator.com/question/23541/possible-to-open-all-webview-links-in-new-window

    — commented 9 months ago by Aaron Saunders

  • I'm already having issues with injecting text into the web page as noted above. There is no chance any of the links will ever be local, so thats not an option. Are you sure there isn't a Tiapp setting for this? I can't imagine this is a "feature" for Android. Why would anyone want open up multiple web browser windows on a mobile device anyway?

    — commented 9 months ago by Francis Meetze

Your Answer

Think you can help? Login to answer this question!