Webview/HTML Item External Links

Not sure if im going about this the right way, but I have a floating menu that opens a website (google keep) in webview. If I click on any external links, it doesnt do anything, so im wondering if using the script function can tell it to open external links in the default browser, and if possible what that script would be.

also, is there a way to background pre-load the floating menus?

I will soon provide these options (choosing external URL handler and preload).
For now you could execute a simple function that hooks into links and/or the window.open function:


let openFunc = async (url) => {
    //make use of BTT's Open URL action:
    let actionDefinition = {
      "BTTOpenURLBrowser" : "Default",
      "BTTPredefinedActionType" : 59,
      "BTTOpenURL" : url,
    }

    let result = await trigger_action({json: JSON.stringify(actionDefinition), wait_for_reply: false});

}


window.open = openFunc;

// overriding like this will open any a href link in the external browser. You could modify this to only apply to external links, e.g. by checking whether it starts with http before passing to openFunc
document.onclick = function (e) {
  e = e ||  window.event;
  let element = e.target || e.srcElement;

  if (element.tagName == 'A') {
    openFunc(element.href);
    return false; // prevent default action and stop event propagation
  }
};
1 Like

thanks!