PopupWindow

Summary: create popup windows
Version: 2023-06-17
Prerequisites: pmwiki 2
Status: stable
Maintainer: DaveG
Categories: Links
Version: 2017-04-23
Prerequisites: PmWiki 2.2.56 or newer (compatible with PHP 5.5+)
Categories: PHP55
Download: popupwindow-2017-04-23.phpΔ (solves problem with PHP 5.5 preg_replace() incompatibility)
Download: popupwindow_2023_06_17.phpΔ (works with PMWiki 2.3)

See also : "Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead".

Questions answered by this recipe

How can I create popup windows?

This section is optional; use it to indicate the types of questions (if any) this recipe is intended to answer.

Description

Enter your recipe's description here. Download popupwindow.phpΔ, copy to in cookbook directory and install by adding to local customisation file:

include_once("$FarmD/cookbook/popupwindow.php");

This adds the markup %popwin parameters%[[link]]. [[link]] is a standard wiki link. Parameters can be none for default popup, or any of the following (defaults are shown):

  • id= 0, give each popup link a different id number.
  • width= 500, window width in pixels .
  • height= 300, window height in pixels.
  • left= center, window position from left in pixels. left=center will horizontally center the popup window to the screen.
  • top= center, window position from top in pixels. top=center will vertically center the popup window to the screen.
  • resizable= 1, boolean, window can be resized.
  • scrollbars= 1, boolean, show scrollbars.
  • toolbar= 0, boolean, hide toolbar.
  • location= 0, boolean, hide url location bar.
  • directories= 0, boolean, hide links bar.
  • statusbar= 0, boolean, hide statusbar .
  • menubar= 0, boolean, hide menu bar.

Some of these will not always work in all browsers. Some are dependant on user settings in the browser. Popup links can be configured to pass different parameters for different links, by adding a unique id= number as a parameter.

Additional markup:

  • (:popclose Close Window:) creates a link for closing the popup window, replace "Close Window" with whatever label text.
  • (:input closewindow 'Close Window':) creates a 'Close Window' button. Replace "Close Window" with whatever label text.
  • ?action=popopen used in the link which opens the popup will set a page variable {$PopOpen}. This can be used in the popup page in conditionals to trim side menus etc:
(:if equal {$PopOpen} 1:)(:noleft:)(:popclose Close Window:)(:ifend:)

This will ensure the page functions normally when not opened as a popup, but it opens without the SideBar and with a "Close Window" link when "popped up" with %popwin% and when adding ?action=popopen to the link as here:

%popwin%[[PageName?action=popopen| link text]]

Examples:

%popwin%[[Group.PageName]] : popup a default window, centered to screen.
%popwin top=20 left=20%[[Group.PageName| link-text]] : popup a default window 20px from left and top.
%lfloat%%popwin%[[Group.PageName| Attach:thumb.jpg]] : float a picture link, popup a default window.
%popwin width=300 height=200 scrollbars=0%[[Group.PageName]] : popup a window size 300 by 200 with no scrollbars.

Notes

Release Notes

  • 2008-04-17: Added (:input closewindow 'Close Window':). Modified (:popclose label:) markup to make it more secure. Changed function so javascript gets loaded as part of the popup link.
  • 2007-03-20: Added (:popclose label:) markup for link to close popup. Added action=popopen which creates a page variable {$PopOpen}. This can be used in conditionals in the popup page.
  • 2006-11-20b: Changed default position from top left corner to screen centered.
  • 2006-11-20a: Revised markup. Added another markup to cater for [[linktarget | linktext]]-type links
  • 2006-11-20: Initial release.

Comments

There's an annoying side effect when using images in link descriptions: the width and height parameters are both interpreted for the popup window geometry and the description image size, as in: %popwin width=300 height=200 scrollbars=0%[[Group.PageName|Attach:FaultyResizedImage.jpg]]
-- Dfaure February 11, 2007, at 04:58 PM

  • This problem isn't happening for me. Let's get the recipe enabled on this page and see how it works; I've added "update me" to the category. -- Tegan Dowling

Has anyone tried using this for a link in the sidebar when the current page is not "Site.Sidebar"? For example, edit the sidebar to use this, save, then navigate somewhere else. Does the sidebar link still work? -- lordmundi July 10, 2007, at 07:48 AM

See Also

Contributors

Sandbox

%popwin width=700 height=500%[[Test.PopUp]] without action=popopen

%popwin width=700 height=500%[[Test.PopUp?action=popopen| PopUp]]

normal:%newwin%[[Test.PopUp| PopUp]]

%popwin width=600 height=400%[[http://www.google.com|Google]]

Test.PopUp without action=popopen

PopUp

normal:PopUp

Google

%popwin width=700 height=500%[[Test.PopUpTrimmed]] popup a trimmed page

Test.PopUpTrimmed popup a trimmed page

Comment

Hi - Thanks for this cookbook. I really like $PopOpen features which works great except I have fixflow skin, which has an extra header menu called PageTopMenu and an extra footer menu called PageFootMenu. The commands to turn these off are (naturally) notopmenu and nofootmenu and are built into the skin. So at the end of each page that I want to use both as a regular page and a popup window, I add the line

(:if equal {$PopOpen} 1:)(:noleft:)(:noright:)(:noheader:)(:nofooter:)
(:notopmenu:)(:nofootmenu:)(:popclose Close Window:)(:ifend:)

and then on the page where I want the link to bring up a trimmed popup window I write the link as:

%popwin%[[myPopupPageLink?action=popopen|myPopupPageLink Text]]

and get a perfectly trimmed page with the Close Menu button. Thanks. LFS


Hi, I'm having a ton of problems getting this to work. I'm trying to create a default pop-up that will work without me even clicking on a link. That pop-up will be a warning. So, I want people to visit my website and every time they click somewhere, there must be a pop-up automatically coming up giving them a small disclaimer page. Alternatively, I would just set that up on the homepage, but how do I set it automatically? I need step-by-step instructions.

Thanks!

Chris

P.S. I forgot to add I'm using the Monobook skin.

popup on a click anywhere sounds horrendous. You want tons of annoyed visitors? And how can they navigate if bombarded with popups? Or do you just want to stop visitors right-clicking, to stop easy downloading of photos? HansB July 14, 2008, at 08:59 AM

Hans,

You are right that it sounds horrendous, but I have to do it in order to implement a wiki site in my organization. The IT security folks said that was a condition, so there is no choice involved. Maybe what I could do is just have a pop-up every time someone visits the homepage. How do I do that?

Thanks,

Chris

How about putting the disclaimer into a div, with nice frame and background perhaps, on your wiki homepage, and have it closed by clicking a button? You can use Cookbook:ShowHide for this. You can even position the div absolute, if you want to give the impression of a 'window' floating above content. you can include in the div markup style='position:absolute;top:100px;left:100px;width:400px;' etc. for your css, or create a class for it in css. I put an example on the ShowHide page - HansB July 15, 2008, at 07:15 AM

Hans,

Great idea! I looked into this concept and think that this will meet my needs better. On that note, would I be able to have the message show up so they don't have to click to open it? In other words, I want them to get to my homepage and see the disclaimer. In order to get rid of the disclaimer, they have to click on close.

Thanks! July 16, 2008, at 09:56 AM

Edit: I checked your comment again and you answered what I needed to know. Thanks! July 17, 2008, at 10:48 AM

Hans or anyone,

I'm back for more. I've been playing with the show/hide function and this is what I have so far:

(:toggle div=box2 style='position:absolute;top:100px;left:100px;width:400px;':)

Remember that you may not post any content that could be considered rude, offensive, slander, or otherwise harmful to the community that will be reading all posts.

That text does not float above my content and is almost just another part of the website. I would like a dark grey or blue box with red text that hovers over the content of a page with that text that could show/hide. Is there a way to get that to work?

As always, thanks!July 24, 2008, at 18:06 PM


Chris: You'd need to use 'position:fixed' in order to make the text appear in the same position regardless of how the window viewport was scrolled. However, IE6 has issues with fixed positioning, so this may or may not work for you.
 ~ ~ DaveG

Dave,

Thanks for your comment. I realized I was being uberly new to this, all I had to do is to click "edit" and copy and paste the source code already provided for pop up. Thanks! Chris


Wow, great recipe! I was trying to figure out how to embed some really funky html and javascript in my wiki without opening it up to too many risks. But the popup window recipe solved all that - I can simple create a link to a small popup window.

Matt L? August 30, 2008, at 10:17 PM


I have been using this recipe for months and think it fantastic, but I was bummed thinking I could only have one popup window - then I saw the id=number option. This is such a great recipe!! LFS 4 September 2008

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.