How to create url preview in JavaScript?

你说的曾经没有我的故事 提交于 2019-12-04 03:53:54

You need to have pre-stored images. Javascript cannot take screenshots and resize the images (for now). Try this: http://snapcasa.com/ . It takes images dynamically for you. All you have to do is to hot link the images :)

The best features when using http://snapcasa.com/:

  1. Images are guaranteed to be most up-to-date

  2. You don't have to store them on your server!

  3. Free plan has lots of credits for you to burn!

Daniel is right there is no way the client could do this, but an option would be a free thumnail service; http://www.webresourcesdepot.com/10-free-website-thumbnail-generation-services/ combined with a nice tooltip script: http://flowplayer.org/tools/tooltip.html

If you want more direct control over your screenshots and want to configure things on the server, you can set up khtml2png or webkit2png* to generate images on the command line. (And here is some direction toward using Gecko if you prefer that.)

* webkit2png provides instructions for OS X, but there's really no reason it shouldn't work on *nix, being that WebKit itself is cross-platform. Figuring that out can be left as an exercise to the reader, but it may be worthwhile as KHTML has historically lagged behind WebKit for new (HTML5, CSS3, etc) features.

I haven't tested any of these solutions, but it might be enough to get started if you want more control over the screenshot generation.

Website previews cannot be generated on the client-side. The preview image needs to be rendered on the server, which can then be called into your HTML document with a simple <img> tag.

Basically you could have an image tag such as the following:

<img src="/my_preview_renderer.php?site=www.google.com" />

... where my_preview_renderer.php will generate the preview in realtime and return the image data with the appropriate mime-type. You can use any server side scripting language.

This is not an exhaustive answer, but I hope that it can point you to the right direction.

You can do this using an iframe, or pay for a service that takes screenshots (Doctype.com offer this, I think). The paid service will still take a long time to generate screenshots. Basically, don't bother trying, it's not going to work.

well, i think since all answers here are a bit old, now you can do this using the built in web-kit tools in most current browsers, using webrtc,or ffmpeg tools available in js such an approach can be done in minutes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!