开发者

Is it possible to use a jQuery pagination script and print the results in a separate window?

开发者 https://www.devze.com 2023-02-07 03:42 出处:网络
I have a jQuery pagination script that I\'ve downloaded and want to use it on a page where the user can page through the data and then, using a print button on that page, print t开发者_开发知识库he sp

I have a jQuery pagination script that I've downloaded and want to use it on a page where the user can page through the data and then, using a print button on that page, print t开发者_开发知识库he specific page they want.

The print button currently opens a pop-up window with a printer friendly layout. I need to somehow pass the paginated data over to this new window. I can do this with a PHP script by passing a GET variable with the page number to the new window but I'm pretty clueless with how to do this with JavaScript or if it's even possible at all.

Can someone tell me if what I'm wanting here can be done? If it can, I'd be happy to post some code.


Something like this should work:

$(function(){

    // http://www.bennadel.com/blog/695-Ask-Ben-Getting-Query-String-Values-In-JavaScript.htm
    var objURL = new Object(),
        printButton = ".print",
        key = "page_id",
        value = "";

    window.location.search.replace(
        new RegExp( "([^?=&]+)(=([^&]*))?", "g" ),
        function( $0, $1, $2, $3 ){
            objURL[ $1 ] = $3;
        }
    );
    value = objURL[key];

    $(printButton).click(function(){
        var url = "http://google.com?" + key + "=" + value;
        window.open(url, "_blank");
        return false;
    });

});

This creates an object objURL which contains the name-value pairs of the query string. Then you just attach a click handler to a print button that fires window.open() with the proper query string.

0

精彩评论

暂无评论...
验证码 换一张
取 消