php - Javascript "print contents of div" function repeating the same content -


i attempting edit wordpress plugin client used print coupon using custom javascript function print contents of div. plugin called shortcode:

[print-button target='div#foo']

the target css id of container div jpg of coupon being content. when click on generated "print" button window opens , brings print dialogue jpg. 1 instance of plugin on page works perfectly, when have 2 or more instances jpg opens in new print window last 1 on page. here plugin 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 = "<input id=\"coupon\" type='button' onclick='return pop_print()' value='print coupon'/>       <script type='text/javascript'>     function pop_print(){         w=window.open(null, 'print_page', 'scrollbars=yes');         w.document.write(jquery('$target_element').html());         w.document.close();         w.print();     }     </script>";       return  $output; } 

i have echo'd out $target_element variable @ end of function , list each 'target' variable correctly. cannot figure out why last instance's image showing when click "print" button every other instance. i'm assuming it's simple in javascript i'm not seeing.

i not original author of plugin, , contacting them not option.

thank help.

because, when have more 1 instances of "buttons", have several definition of function "pop_print" static code. and, of course, last function executes.

try send target element argument of function "pop_print".

example:

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 = "<input id=\"coupon\" type='button' onclick='return pop_print(\'$target_element\')' value='print coupon'/>       <script type='text/javascript'>     function pop_print(target_element){         w=window.open(null, 'print_page', 'scrollbars=yes');         w.document.write(jquery(target_element).html());         w.document.close();         w.print();     }     </script>";       return  $output; } 

and, of course, try replace function plug-in external js file.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -