How to Take Screenshot of Website from URL using Jquery

Screenshot

If you sore to display image Preview of any website from url, You can clearly use Jquery considering Google PageSpeed Insights API to seize the realtime Screenshot of the website. Like if your website displaying the numbers of url on the subject of page therefore it is comfortable idea to display website image preview to users for improved user experience, Here Ill take movement you How to Take Screenshot of Website from URL using Jquery and you can use along with script in any technology to occupy screenshot of website.

How to Take Screenshot of Website from URL using Jquery

You can handily make call to previously Google PageSpeed Insights url using javascript or PHP itll reward data which you can parse and display website image preview.

https://www.googleapis.com/pagespeedonline/v1/runPagespeed?url=' + url + '&screenshot=true

Making ajax call and parsing json data to get image preview

$.ajax({
        	url: 'https://www.googleapis.com/pagespeedonline/v1/runPagespeed?url=' + url + '&screenshot=true',
        	context: this,
        	type: 'GET',
        	dataType: 'json',
        	timeout: 60000,
        	success: function(result) {
           		var imgData = result.screenshot.data.replace(/_/g, '/').replace(/-/g, '+');
            	$("img").attr('src', 'data:image/jpeg;base64,' + imgData);
            },
            error:function(e) {
            	$("#msg").html("Error to fetch image preview. Please enter full url (eg: http://www.iamrohit.in)");
            }
        });

Using above shape on i created easy input box in html where you infatuation to enter full website residence and itll call above innocent Google PageSpeed Insights url and reward image preview of website.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.