WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] open external link within a defined pop up window

[Resolved] open external link within a defined pop up window

Viewing 15 replies - 16 through 30 (of 42 total)
  • howz that? http://pastebin.com/06qZbcBd

    Perfect.
    Now, look for the last two lines (539 and 539), They should look like this:

    }
    endif;

    Right under that, paste the PHP code I gave you. You can leave a line between the endif and the first line of my code, for clarity:

    }
    endif;
    
    /* code here */

    After you paste the code, do another pastebin of functions.php so I can make sure it’s well placed.

    http://pastebin.com/rbSvKTQE

    Ok, my code is good but you have two errors in lines 350 and 353. It seems some extra line breaks got inserted by accident. To fix them, replace these lines:

    <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment-
    
    >comment_ID ) ); ?>">
    			<?php
    				/* translators: 1: date, 2: time */
    				printf( __( '%1$s at %2$s', 'twentyten' ), get_comment_date(),  get_comment_time() ); ?
    
    ></a><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' );
    			?>

    with these:

    <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
    			<?php
    				/* translators: 1: date, 2: time */
    				printf( __( '%1$s at %2$s', 'twentyten' ), get_comment_date(),  get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)', 'twentyten' ), ' ' );
    			?>

    OK, this is done. What next?

    Well, the good news is that the script is now being inserted in your page. The bad news is that it’s not working, which is weird because it worked on my test site. Try this code instead:

    function lidget_popup_link() {
    ?>
    <script type="text/javascript">
    	jQuery(window).load(function() {
    		var width = "680", /* Enter popup window width here */
    			height = "480", /* Enter popup window height here */
    			menuItem = "menu-item-47", /* Enter menu item ID */
    			target = "#"+menuItem+" a",
    			hrefVal = jQuery(target).attr("href")
    		;
    		jQuery(target).attr({
    			"href" : "#",
    			"onclick" : "window.open('"+hrefVal+"','','width="+width+",height="+height+",scrollbars=no,resizable=no,location=no,menubar=no,toolbar=no')"
    		});
    	});
    </script>
    <?php
    }
    add_action('wp_head', 'lidget_popup_link');
    ?>

    OK, I have replaced the code at functions.php

    I forgot to replace the menu-item number when I repasted the code. Just fixed it.

    Edit: I just realized your site is not loading jQuery (smacks himself in the head with a huge bat). This should do the trick for sure.

    function lidget_popup_link() {
    ?>
    <script type="text/javascript">
    	jQuery(window).load(function() {
    		var width = "680", /* Enter popup window width here */
    			height = "480", /* Enter popup window height here */
    			menuItem = "menu-item-783", /* Enter menu item ID */
    			target = "#"+menuItem+" a",
    			hrefVal = jQuery(target).attr("href")
    		;
    		jQuery(target).attr({
    			"href" : "#",
    			"onclick" : "window.open('"+hrefVal+"','','width="+width+",height="+height+",scrollbars=no,resizable=no,location=no,menubar=no,toolbar=no')"
    		});
    	});
    </script>
    <?php
    }
    add_action('wp_head', 'lidget_popup_link');
    
    function lidget_call_jquery() {
    	wp_enqueue_script('jquery');
    }
    add_action('wp_enqueue_scripts', 'lidget_call_jquery');
    ?>

    I’ve fixed it too.
    What next?

    See my edit above. Sorry I missed that! ๐Ÿ˜‰

    ho my goodness, I changed menu-item-47 after I pasted your code and it works! superb. Thank you very much indeed

    just one more thing, if I was to attempt a link from the body text to this same pop-up window, how would I go about this?

    Cool! Glad it’s working. I don’t quite understand what you mean about fetching the link from the “body text”. Where exactly would it be?

    see on the home page I have links contained within the body text? well, how would I link the phrase “If itโ€™s a

      new garage

    to the same URL and pop up window?

    Hi. You would have to turn the click here text into a link and add it to your body text, wherever those are being called from.
    The exact code for it would be:

    <a title="New Garages" target="_blank" href="#" onclick="window.open('http://www.4concretegarages.com/quotation/step1.asp','','width=680,height=480,scrollbars=no,resizable=no,location=no,menubar=no,toolbar=no')">click here</a>

    Remember that if you change your contact form’s URL, you’ll have to manually update this link as well. Same thing goes for the size of the pop up. You’ll have to configure it manually.
    If you want the whole thing to work automatically from the script (i.e., have the script take care of both links and pop up sizes by itself using the script options), the body text link should look like this:

    <a class="lidget-popup" title="New Garages" target="_blank" href="#">click here</a>

    and then you would need to replace the script part (the rest remains the same) with this version:

    <script type="text/javascript">
    	jQuery(window).load(function() {
    		var width = "680", /* Enter popup window width here */
    			height = "480", /* Enter popup window height here */
    			menuItem = "menu-item-47", /* Enter menu item ID */
    			target = "#"+menuItem+" a",
    			hrefVal = jQuery(target).attr("href")
    		;
    		jQuery(target).attr({
    			"href" : "#",
    			"onclick" : "window.open('"+hrefVal+"','','width="+width+",height="+height+",scrollbars=no,resizable=no,location=no,menubar=no,toolbar=no')"
    		});
    		jQuery(".lidget-popup").attr("onclick", "window.open('"+hrefVal+"','','width="+width+",height="+height+",scrollbars=no,resizable=no,location=no,menubar=no,toolbar=no')");
    	});
    </script>

    With this new code, all links with the CSS class lidget-popup will be turned into pop up links (and point to the same URL as your menu item’s).
    Cheers!

Viewing 15 replies - 16 through 30 (of 42 total)
  • The topic ‘[Resolved] open external link within a defined pop up window’ is closed to new replies.