[Casper] New blank tab when signing in from members only post


I am using the Casper theme for my site and I have member-only posts enabled. When I try to sign in from a members-only post, then a new about:blank tab opens. The login popup also shows, but I first have to close the new tab which is quite annoying. I am a beginner in web development, but I figured that there is an extra event listener on the “Sign up” buttons and “Sign in” link. (See image below)

When I remove them the problem is fixed. Where are these event listeners generated and how can I remove the extra (index) listener you can see in the screenshot?


- How was Ghost installed and configured?
I am running Ghost on pikapods.com

- What Node version, database, OS & browser are you using?
Unknown (managed by pikapod), mysql8, unknown (managed by pikapod), Chrome on ChromeOS (but same happens on Firefox on Windows/Linux)

- What errors or information do you see in the console?
I do not see any error, but there is this extra event listener you can see in the screenshot or find yourself when using the link.

- What steps could someone else take to reproduce the issue you’re having?
Open the link. Use inspect element to see what event listeners are on the element.

It looks like you have a script so that all links open in a new tab, which is what’s causing the blank screen. When people click the signup link, the new tab opens.

You either have to remove this script or filter out the portal links…

<script type="text/javascript">
    var links = document.querySelectorAll('a');
    links.forEach((link) => {
        var a = new RegExp('/' + window.location.host + '/');
        if(!a.test(link.href)) {
            link.addEventListener('click', (event) => {
                window.open(link.href, '_blank');
1 Like

Hey Ryan,

Thanks a lot for your reply! This really helps me and I think I can fix the issue from here. I have two follow-up questions if you or anyone on this forum is in the occasion.

  • Would you have any idea where this script comes from? How was it generated?
  • How does it come that internal links to pages on the website do not open in new tabs?

Thanks again for your help

No problem!

The script could be coming from one of two places. First, it could have been entered in SettingsCode Injection → Site footer. Second, it could be somewhere in the theme, likely in default.hbs. It would be near the bottom of the file.

The script checks if the link in question matches the hostname (!a.test(link.href)). This means, e.g., does mysite.com/about match mysite.com. If it does, then the link is skipped.

However, with the subscription links, there’s no href value because they’re powered by JavaScript. Because of that, they’re not captured by the script. (!a.test(link.href) && link.href !== "" should capture those cases, too)

1 Like

I found it in the Code Injection section like you pointed out. I added the condition and now it works. Thanks a lot again, Ryan!