News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Opening a link in a popup window

Started by hungarianguy, February 12, 2022, 04:19:43 PM

Previous topic - Next topic

hungarianguy

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.

Dzonny

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>

hungarianguy

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.

Dzonny

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>';

hungarianguy

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?

Dzonny

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.

Arantor

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.
Holder of controversial views, all of which my own.


hungarianguy

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.

Arantor

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 :(
Holder of controversial views, all of which my own.


Dzonny

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.

Doug Heffernan

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.

hungarianguy

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.

Doug Heffernan

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 :)

Advertisement: