Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6234319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:27:50+00:00 2026-05-24T10:27:50+00:00

I am working on one project and I am using JavaScript code to get

  • 0

I am working on one project and I am using JavaScript code to get a screenshot of the website.

The screenshot is working fine and is rendered nicely on the page.
What I want to do is instead of displaying it on the page, I want to show the ‘save as’ popup window with the screenshot.

Here is the current code which displays the image on the page:

<script type="text/javascript"> 
    
    var date = new Date();
    var message,
    timeoutTimer,
    timer;
    
    var proxyUrl = "http://html2canvas.appspot.com";
    
    function addRow(table,field,val){
        var tr = $('<tr />').appendTo( $(table));
       
        tr.append($('<td />').css('font-weight','bold').text(field)).append($('<td />').text(val));
        
        
        
    }
    
    function throwMessage(msg,duration){
    
        window.clearTimeout(timeoutTimer);
        timeoutTimer = window.setTimeout(function(){
            message.fadeOut(function(){
                message.remove();   
            });                   
        },duration || 2000);
        $(message).remove();
        message = $('<div />').html(msg).css({
            margin:0,
            padding:10,
            background: "#000",
            opacity:0.7,
            position:"fixed",
            top:10,
            right:10,
            fontFamily: 'Tahoma' ,
            color:'#fff',
            fontSize:12,
            borderRadius:12,
            width:'auto',
            height:'auto',
            textAlign:'center',
            textDecoration:'none'
        }).hide().fadeIn().appendTo('body');
    }
    
    $(function(){
        
        $('ul li a').click(function(e){
            e.preventDefault();
            $('#url').val(this.href);
            $('button').click();                  
        })
        
        var iframe,d;
        
        

        
        $('input[type="button"]').click(function(){
            $(iframe.contentWindow).unbind('load');
            $(iframe).contents().find('body').html2canvas({
                canvasHeight: d.body.scrollHeight,
                canvasWidth: d.body.scrollWidth,
                logging:true
                                    
            });             
            
        });
        
        $('button').click(function(){
            
            $(this).prop('disabled',true);
            var url = $('#url').val();
            $('#content').append($('<img />').attr('src','loading.gif').css('margin-top',40));
            
            var urlParts = document.createElement('a');
            urlParts.href = url;
            
            $.ajax({
                data: {
                    xhr2:false,
                    url:urlParts.href
                    
                },
                url: proxyUrl,
                dataType: "jsonp",
                success: function(html){
                    
                    
                    iframe = document.createElement('iframe');
                    $(iframe).css({
                        'visibility':'hidden'
                    }).width($(window).width()).height($(window).height());
                    $('#content').append(iframe);
                    d = iframe.contentWindow.document; 
                   
                    d.open();
                    
                    $(iframe.contentWindow).load(function(){

                        timer = date.getTime();
                        
                        $(iframe).contents().find('body').html2canvas({
                            canvasHeight: d.body.scrollHeight,
                            canvasWidth: d.body.scrollWidth,
                            logging:true,
                            proxyUrl: proxyUrl,
                            logger:function(msg){
                                $('#logger').val(function(e,i){
                                    return i+"\n"+msg;
                                });
                                
                            },
                            ready: function(renderer) {
                                $('button').prop('disabled',false);
                                $("#content").empty();               
                                var finishTime = new Date();
              
                                var table = $('<table />');  
                                $('#content')
                                .append('<h2>Screenshot</h2>')
                                .append(renderer.canvas)
                                .append('<h3>Details</h3>')
                                .append(table);
                                
                                
                                
                                addRow(table,"Creation time",((finishTime.getTime()-timer)/1000) + " seconds");
                                addRow(table,"Total draws", renderer.numDraws);
                                addRow(table,"Context stacks", renderer.contextStacks.length);
                                addRow(table,"Loaded images", renderer.images.length/2);
                                addRow(table,"Performed z-index reorder", renderer.needReorder);
                                addRow(table,"Used rangeBounds", renderer.support.rangeBounds);
                      


                                throwMessage('Screenshot created in '+ ((finishTime.getTime()-timer)/1000) + " seconds<br />Total of "+renderer.numDraws+" draws performed",4000);
        
        
                         
                            }
                                    
                        });

                    });

                    $('base').attr('href',urlParts.protocol+"//"+urlParts.hostname+"/");
                    html = html.replace("<head>","<head><base href='"+urlParts.protocol+"//"+urlParts.hostname+"/' />");
                    if ($("#disablejs").prop('checked')){
                        html = html.replace(/\<script/gi,"<!--<script");
                        html = html.replace(/\<\/script\>/gi,"<\/script>-->");
                    }
                    // console.log(html);
                    d.write(html);
                    d.close();                         
                }                
            });                                    });                                                                            
    });        
</script> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:27:51+00:00Added an answer on May 24, 2026 at 10:27 am

    For that you can use canvas2image.

    I guess you could put in your ready function:

    ready: function(renderer) {
      ....
      Canvas2Image.saveAsPNG(renderer.canvas);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using PostgreSQL in a project I am working on, and one of
I am working on a web application project using Tapestry 5 framework/javascript. This application
I'm working chequePrinting project using windows-form, where one of my requirement is to print
I'm currently working on a project using javascript and python with Jquery Datatables plugin
The question really says it all. For one project I am working on, the
One long term project I have is working through all the exercises of SICP.
I am only one person working on project - so I am developer without
I'm working on a project which stores single images and text files in one
My team is working on a conversion project to convert one product (but with
On this project I am working on right now, one of the newest feature

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.