Close window link
-
Hi there π
Is there a way to close the pop window by clicking on a link (e.g. Close this window) ?
This would be really helpful
-
This needs to be addresed in the page that is popped up rather than the page that contains the link that causes the page to pop up.
I have created a plugin to add a “Close this Window” link to a page that has been popped up from alligator popup or alligator menu popup:
<?php /* Plugin Name: Alligator Popup Close Button Description: Shortcode to create a link to close a page popped up via alligator popup or alligator menu popup. Author: Michael Atkins Version: 1.0.0 beta Author URI: http://cubecolour.co.uk/ License: GPLv3 Copyright 2015 cubecolour Licenced under the GNU GPL: This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // ============================================== // Prevent Direct Access of this file // ============================================== if ( ! defined( 'ABSPATH' ) ) exit; // Exit if this file is accessed directly // ============================================== // shortcode to add a 'Close this window' link // usage: [closepopup] // ============================================== function cc_close_popup_shortcode( $atts, $content = null ) { $closelink = '<script language="javascript">'; $closelink .= 'function CloseWindow() {'; $closelink .= 'window.close();'; $closelink .= '}'; $closelink .= '</script>'; $closelink .= '<a class="popup-close-button" href="javascript:CloseWindow()">Close This Window</a>'; echo $closelink; } add_shortcode( 'closepopup', 'cc_close_popup_shortcode' );To use this, add a
[closepopup]shortcode where you want the link to appear on the page you have created as the popup.This can be styled as a static button by adding some CSS rules to your child theme’s stylesheet – eg:
a.popup-close-button { background: #444; border: 1px solid #fff; border-radius: 30px; color: #fff; display: block; font-size: 16px; line-height: 1; padding: 10px; position: fixed; bottom: 20px; right: 50%; width: 200px; margin-right: -100px; text-align: center; } a.popup-close-button:hover, a.popup-close-button:active { background: #f660ab; color: #fff; }Hello. Just started using the plugin. Very cool. However, I don’t understand how the plugin to the close the window is any different than the visitor clicking on the ‘X’.
On the page that pops up, I have a button that links to an underlying page. I didn’t have ‘open in a new window’ checked, so the underlying page opened in the same popup window. I got around this by enabling ‘open in a new window’.
Now, as the other posted noted…the popup window stays behind. It would be amazing if the popup windows closed automatically when following a link that takes you outside of the popup page.
You can also click the window’s × button, but the question asked was how to add a link. This might be useful to make a ‘dismiss’ button or the solution could be tweaked to provide a link at the end of a large amount of text to dismiss the window after the text has been read.
The topic ‘Close window link’ is closed to new replies.