In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to use JavaScript to realize screenshot function". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the idea of Xiaobian and go deep into it slowly to study and learn "how to use JavaScript to realize screenshot function" together!
1. Blob media type must be "image/svg+xml"
2. Need an svg element
3. Insert a foreignObject element inside the svg element
4. Put the html that conforms to the specification inside the foreignObject element
Converting dom to canvas is as simple as that, just a few steps above. Here is a simple demo from the documentation:
Document var canvas = document.getElementById('canvas'); var ctx = canvas.getContext('2d'); var data = '' + '' + '' + 'I like ' + '' + 'cheese' + '' + '' + ''; var DOMURL = window.URL || window.webkitURL || window; var img = new Image(); var svg = new Blob([data], {type: 'image/svg+xml'}); var url = DOMURL.createObjectURL(svg); img.onload = function() { ctx.drawImage(img, 0, 0); DOMURL.revokeObjectURL(url); } img.src = url;
Copy the code, run it, wow, cool, two lines of art appeared on the browser!
Hmm, so it's so easy to convert dom into canvas? Then I take out all the doms in the body through document.body[xss_clean] and put them in the foreignObject element. Isn't that OK and intercept the whole page?
The demo is just a Hello World, but the Dom structure in the actual project is much more complex than this, for example, introducing external stylesheets, images, and possibly some tags that do not conform to the xml specification (e.g. missing closing tags, etc.). For a simple example,.container is not defined in the style tag, but in the style tag. The font is red, and the style does not take effect after it is converted to an image.
Document .container { color: red; } Hello World!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.