Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript "print contents of div" function repeating the same content
    primarykey
    data
    text
    <p>I am attempting to edit a Wordpress plugin for a client which is used to print a coupon by using a custom javascript function to print the contents of a div. This plugin is called by a shortcode: </p> <p><code>[print-button target='div#foo']</code></p> <p>The target is the css ID of a container div with a jpg of a coupon being the only content. When you click on the generated "print" button then a window opens and brings up a print dialogue for the jpg. With one instance of this plugin on a page it works perfectly, however when you have two or more instances then the only jpg that opens in the new print window is the last one on the page. Here is the plugin code:</p> <pre><code>add_shortcode("print-button", "sc_show_print_button"); function sc_show_print_button($atts, $content = null){ $target_element = $atts['target']; if($target_element == ''){$target_element = "document.body";} $output = "&lt;input id=\"coupon\" type='button' onClick='return pop_print()' value='Print Coupon'/&gt; &lt;script type='text/javascript'&gt; function pop_print(){ w=window.open(null, 'Print_Page', 'scrollbars=yes'); w.document.write(jQuery('$target_element').html()); w.document.close(); w.print(); } &lt;/script&gt;"; return $output; } </code></pre> <p>I have echo'd out the $target_element variable at the end of the function and it does list each 'target' variable correctly. I just cannot figure out why only the last instance's image is showing up when you click the "print" button for every other instance. I'm assuming that it's something simple in the javascript that I'm not seeing.</p> <p>I am not the original author of this plugin, and contacting them is not an option.</p> <p>Thank you for your help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload