1

I am calling screenView() from another class. I am able to call it but I am not getting strDataURI. What am I doing wrong?

       function screenView(){
            var image;

             var date = new Date();
             var message,
             timeoutTimer,
             timer;

             var proxyUrl = "http://html2canvas.appspot.com";
             var iframe,d;

             $(this).prop('disabled',true);
             var url = "http://www.facebook.com/google";

             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; 
                    alert("d-----"+d);
                     d.open();

                        $(iframe.contentWindow).unbind('load');
                         alert("inside>>"+ $(iframe).contents().find('body'));
                     $(iframe).contents().find('body').html2canvas({
                         canvasHeight: d.body.scrollHeight,
                         canvasWidth: d.body.scrollWidth,
                         logging:true

                     }); 
                     alert("inside before load view");
                     $(iframe.contentWindow).load(function(){

                         alert("inside view");

                         $(iframe).contents().find('body').html2canvas({
                             canvasHeight: 30,
                             canvasWidth: 10,
                             logging:true,
                             proxyUrl: proxyUrl,
                             logger:function(msg){
                                 $('#logger').val(function(e,i){
                                     return i+"\n"+msg;
                                 });

                             },
                             ready: function(renderer) {
                                 alert("in side ready renderer");
                                 $('button').prop('disabled',false);
                                 $("#content").empty();               
                                 var finishTime = new Date();
                                     var strDataURI = renderer.canvas.toDataURL("image/jpeg"); 
                                     image = strDataURI

                                     alert("last"+strDataURI);
                                     d.close();
                             }

                         });

                     });



                 }


             });
             return image;

        }
Peter Bridger
  • 9,123
  • 14
  • 57
  • 89
vinod
  • 11
  • 1
  • 1
  • 3
  • probably renderer.canvas.toDataURL is asynchronous function, it can't give result immediately – megas Aug 16 '11 at 09:32

1 Answers1

4

Why don't you try this: http://hertzen.com/experiments/jsfeedback/

This example has worked for me

Dan
  • 1,518
  • 5
  • 20
  • 48