Open New Window/Tab via API

AI-generated summary

In a support thread titled ‘Open New Window/Tab via API,’ olegbc1 seeks to modify their Discourse instance so that clicking the community logo opens a custom URL in a new tab. They’ve added a script using api.changeWidgetSetting to change the logo’s href, but adding target: '_blank' causes an error and reverts the logo to the homepage. jordan.vidrine suggests a workaround from a related thread, sharing a code snippet that uses api.decorateWidget to inject a custom link with target='_blank' into the header. They also direct olegbc1 to a specific reply in the referenced topic, where greg_r confirms the solution works when placed in the </head> section of the theme. The issue appears to stem from changeWidgetSetting not supporting target attributes directly, requiring a widget decoration approach instead. The discussion highlights a common customization challenge in Discourse themes and offers a working alternative for opening external links in new tabs.

Hello, I’ve customized my instace of discourse to take a user to a specific page when they click on the community logo in the top right. It’s just a customized theme, in the header section:

<script type="text/discourse-plugin" version="0.4">
  api.changeWidgetSetting('home-logo', 'href', 'https://custom-url-here')
</script>

is there any way to make it open the url in the new browser tab?

This may help.

Thanks for the sugestion! I have checked the thread you linked and added a , target:'_blank' to api.changeWidgetSetting. Unfortunately this causes an error and clicking on the top logo takes you back to discourse homepage -

The code below was taken from a reply marked as a solution in a previous topic.

<script type="text/discourse-plugin" version="0.4">
api.decorateWidget('header-buttons:after', helper => { 
const showExtraInfo = helper.attrs.minimized; 
if (!showExtraInfo) { 
return helper.h('a.blog-link', {href:'https://blog.example.com', target:'_blank'}, 'Visit our blog'); } 

});
 </script>

did you visit this topic reply?