Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: hungarianguy on February 12, 2022, 04:19:43 PM

Title: Opening a link in a popup window
Post by: hungarianguy on February 12, 2022, 04:19:43 PM
I want to display a template that I have created in a pop up overlay.  I have added a link in posts which links to my custom template. Everything works fine but my users have asked me that it is easier for them if the link opened the template in a new pop window rather than taking them to a new page. It is a mod that a member of ours coded for us but he has started a new job and has no time for this. Here is my code

', $txt['show_rules_link'], '';
My understanding is that I need to use javascript for it. Can someone please help me out.
Title: Re: Opening a link in a popup window
Post by: Dzonny on February 12, 2022, 06:09:11 PM
I assume that the link itself is added in that text string, right?

The link itself should be something like this:
<a href="http://link.com"
  target="popup"
  onclick="window.open('http://link.com','popup','width=600,height=600'); return false;">
    Open Link in Popup
</a>
Title: Re: Opening a link in a popup window
Post by: hungarianguy on February 13, 2022, 04:17:46 PM
Yes, that is the case @Dzonny. I tried it but I get errors. Can you please tell me how to wrap thi slink in the code that you posted?

echo '
<a href="', $scripturl, '?action=showrules;sa=allrules;rid=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['show_rules_link'], '</a>';

What I am after is to show the template just like it shows when you click the link that shows members who liked a post.
Title: Re: Opening a link in a popup window
Post by: Dzonny on February 13, 2022, 04:53:42 PM
Try something like this:
echo '
<a href="', $scripturl, '?action=showrules;sa=allrules;rid=', $message['id'], ';', $context['session_var'], '=', $context['session_id'], '"  target="popup"
  onclick="window.open(\'http://link.com\',\'popup\',\'width=600,height=600\'); return false;">', $txt['show_rules_link'], '</a>';
Title: Re: Opening a link in a popup window
Post by: hungarianguy on February 13, 2022, 05:21:20 PM
Quote from: Dzonny on February 13, 2022, 04:53:42 PMTry something like this:
echo '
        ', $txt['show_rules_link'], '';

Thank you. It works but it does not open like the likes template where you can see members who liked a post. Is it possible to make it like that?
Title: Re: Opening a link in a popup window
Post by: Dzonny on February 13, 2022, 05:32:57 PM
Oh, that's an ajax script. I'm sure you could use existing one, but I don't have time now to check through the code (display.template.php should be where you should seek for it) to see how it's used for the likes exactly.
Title: Re: Opening a link in a popup window
Post by: Arantor on February 13, 2022, 05:56:19 PM
It's a generic script within SMF (the help popups in admin use it too) - it's a call out to reqOverlayDiv where the first parameter is the URL to call, the second is the title of the little popup window, and the third is the icon to use in the corner.

Note that the popup expects the page to be formatted a certain way, which the terms and rules page does not follow by default, so it's quite a bit more work than it might seem initially.
Title: Re: Opening a link in a popup window
Post by: hungarianguy on February 14, 2022, 08:35:40 AM
Thank you again @Arantor. I copied the code from the permission template files but all it did for me was loading and loading without displaying anything. I am not a coder as you might have guessed but I can follow instructions. If you have sometime can you please post the full code? It will help me a lot.
Title: Re: Opening a link in a popup window
Post by: Arantor on February 14, 2022, 09:15:18 AM
It's really quite a bit of work because while you could feed it the link, you'll potentially end up getting the header and footer embedded inside the pop up which requires special code to work around if you still want it to have the same link it would normally have (needed for the "you need to re-agree the agreement" stuff to work properly too.

I wrote a bunch of this stuff 8 years ago and don't really remember properly any more :(
Title: Re: Opening a link in a popup window
Post by: Dzonny on February 14, 2022, 09:22:37 AM
Just tried with:
<a href="', $scripturl, '?action=helpadmin;help=see_admin_ip" onclick="return reqOverlayDiv(this.href);" class="help">Link here</a>';And it works in Display.template.php.
Now you should change href to custom made text and stuff I guess.
Title: Re: Opening a link in a popup window
Post by: Doug Heffernan on February 27, 2022, 05:34:43 PM
Quote from: hungarianguy on February 13, 2022, 05:21:20 PMIt works but it does not open like the likes template where you can see members who liked a post. Is it possible to make it like that?

You will also need to load the js. Have a look at my Showcase mod, the part where likes are displayed.
Title: Re: Opening a link in a popup window
Post by: hungarianguy on March 02, 2022, 06:11:31 AM
Quote from: Doug Heffernan on February 27, 2022, 05:34:43 PM
Quote from: hungarianguy on February 13, 2022, 05:21:20 PMIt works but it does not open like the likes template where you can see members who liked a post. Is it possible to make it like that?

You will also need to load the js. Have a look at my Showcase mod, the part where likes are displayed.

That did the trick.  Thanks Doug.
Title: Re: Opening a link in a popup window
Post by: Doug Heffernan on March 02, 2022, 05:19:45 PM
Quote from: hungarianguy on March 02, 2022, 06:11:31 AM
Quote from: Doug Heffernan on February 27, 2022, 05:34:43 PM
Quote from: hungarianguy on February 13, 2022, 05:21:20 PMIt works but it does not open like the likes template where you can see members who liked a post. Is it possible to make it like that?

You will also need to load the js. Have a look at my Showcase mod, the part where likes are displayed.

That did the trick.  Thanks Doug.

You are most welcome :)