-2

I am using php.

function as_pdf_link( $strContent )
{
    global $wp_query;

    $strHtml = '
        <div id="aspdf">
            <a href="' . get_bloginfo('wpurl') . '/wp-content/plugins/as-pdf/generate.php?post=' . $wp_query->post->ID .'">
                <span>' . stripslashes( get_option( 'as_pdf_linktext' ) ) . '</span>
            </a>     
        </div>';

    return $strContent . $strHtml;
}

When user clicks link, generate.php will be processed.

I would like to show the result returned from these PHP code with new window using javascript.

How should I do for this?

Kevin
  • 41,694
  • 12
  • 53
  • 70
Nyi Ma Lay Win Lae Aye
  • 6,250
  • 2
  • 13
  • 10

2 Answers2

1

Use target="_blank"

<a target="_blank" href="' . get_bloginfo('wpurl') . '/wp-content/plugins/as-pdf/generate.php?post=' . $wp_query->post->ID .'">
            <span>' . stripslashes( get_option( 'as_pdf_linktext' ) ) . '</span>
        </a> 

Have a look target="_blank" vs. target="_new"

Open in new window with javascript: DEMO

onclick="return fun(this);"

function:

function fun(that){
    console.log(that.href);
    window.open(that.href, "New Window", "height=600,width=600");
    return false;
}
Community
  • 1
  • 1
Manwal
  • 23,450
  • 12
  • 63
  • 93
0

Depending on how fancy you want to get...

Really simple solution: add:

target="_blank" 

to the link tag,

More complicated solution:

Add an onclick handler to the element: Such as is explained here:onclick open window and specific size

Best practices solution:

Write a separate javascript file and bind to the link in question from there.

Community
  • 1
  • 1
Malcolm Diggs
  • 455
  • 2
  • 7