Creating a custom php button with embedded javascript

Since months I didn’t find a solution to create a pdf document from the toolbar pdf button and doing some other php stuff (saving file, email…) with one click on this button.
So I thought about creating a new toolbar php button and implementing the javascript code that triggers the pdf creation in SC.

The javascript code which starts the pdf creation is


javascript: nm_gp_move('pdf', '0', 'cor')

Putting that in a javascript button works fine but when I try to implement the javascript in a php button I can’t get it working.

The implementation in a php button was intended like this

?> (ends the php)
<script>nm_gp_move('pdf', '0', 'cor');</script>
<?php (starts php again)

A click on this php button only brings an empty page with an OK button but no pdf is created? Does anybody know how to get this work?

Actually the code you put inside a PHP button runs in another window/frame other than the current page. So, if you want to execute a function from the (real) current page, you have to specify where the function is (and it’s in the parent/opener window object), like this:


?>
<script>
    if(window.parent != window && typeof window.parent.nm_gp_move == "function"){
        // if target is 'modal'
        window.parent.nm_gp_move('pdf', '0', 'cor');
    }else if(window.opener && typeof window.opener.nm_gp_move == "function"){
        // if target is 'Other Window'
        window.opener.nm_gp_move('pdf', '0', 'cor');
    }
</script>
<?php

Thanks Mamede, seems like it is working now :wink:
Joe

It’s ok, Joe
:wink: