From e86992a7eedd0ae43f571965db2bc44a401337c1 Mon Sep 17 00:00:00 2001 From: Daniel Scalzi Date: Sun, 13 Sep 2020 20:27:18 -0400 Subject: [PATCH] Open anchor hrefs in the default browser. (#111) --- src/renderer/index.tsx | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/renderer/index.tsx b/src/renderer/index.tsx index bc67866..eed7aaa 100644 --- a/src/renderer/index.tsx +++ b/src/renderer/index.tsx @@ -2,20 +2,21 @@ import * as React from 'react' import * as ReactDOM from 'react-dom' import { AppContainer } from 'react-hot-loader' import { Provider } from 'react-redux' -// import { shell } from 'electron' +import { shell } from 'electron' import store from './redux/store' import Application from './components/Application' import './index.css' - -// document.addEventListener('click', (event: MouseEvent) => { -// if ((event.target as HTMLElement)?.tagName === 'A' && (event.target as HTMLAnchorElement)?.href.startsWith('http')) { -// event.preventDefault() -// shell.openExternal((event.target as HTMLAnchorElement).href) -// } -// }) +// Open anchor hrefs in the default browser. +document.addEventListener('click', (event: MouseEvent) => { + const anchor: HTMLAnchorElement | null = (event.target as HTMLElement).closest('a') + if(anchor != null && anchor.hasAttribute('href') && anchor.getAttribute('href')!.toLowerCase().startsWith('http')) { + event.preventDefault() + shell.openExternal(anchor.href) + } +}) // Create main element const mainElement = document.createElement('div')