diff --git a/frontend/src/app.js b/frontend/src/app.js index 78abf153af..cf418ebea3 100644 --- a/frontend/src/app.js +++ b/frontend/src/app.js @@ -135,8 +135,13 @@ class App extends Component { navigate(url, {repalce: true}); } else { let url = siteRoot + 'lib/' + selectedItem.repo_id + '/file' + Utils.encodePath(selectedItem.path); - let newWindow = window.open('about:blank'); - newWindow.location.href = url; + let isWeChat = Utils.isWeChat(); + if (!isWeChat) { + let newWindow = window.open('about:blank'); + newWindow.location.href = url; + } else { + location.href = url; + } } } diff --git a/frontend/src/pages/lib-content-view/lib-content-view.js b/frontend/src/pages/lib-content-view/lib-content-view.js index 9d86854216..d9e626e4de 100644 --- a/frontend/src/pages/lib-content-view/lib-content-view.js +++ b/frontend/src/pages/lib-content-view/lib-content-view.js @@ -1068,9 +1068,14 @@ class LibContentView extends React.Component { if (this.state.currentMode === 'column' && Utils.isMarkdownFile(direntPath)) { this.showColumnMarkdownFile(direntPath); } else { - const w=window.open('about:blank'); const url = siteRoot + 'lib/' + repoID + '/file' + Utils.encodePath(direntPath); - w.location.href = url; + let isWeChat = Utils.isWeChat(); + if (!isWeChat) { + let newWindow = window.open('about:blank'); + newWindow.location.href = url; + } else { + location.href = url; + } } } } diff --git a/frontend/src/utils/utils.js b/frontend/src/utils/utils.js index d15a10542d..905cae7328 100644 --- a/frontend/src/utils/utils.js +++ b/frontend/src/utils/utils.js @@ -38,6 +38,13 @@ export const Utils = { return window.innerWidth >= 768; }, + isWeChat: function() { + let ua = window.navigator.userAgent.toLowerCase(); + let isWeChat = ua.match(/MicroMessenger/i) == 'micromessenger'; + let isEnterpriseWeChat = ua.match(/MicroMessenger/i) == 'micromessenger' && ua.match(/wxwork/i) == 'wxwork'; + return isEnterpriseWeChat || isWeChat; + }, + FILEEXT_ICON_MAP: { // text file