This interface is used for snapshot.
Use snapshot interface
AlipayJSBridge.call('snapshot', function(result) {
console.log(result.success);
});
Code sample
<h1>Click the buttons below to see different snapshot effects</h1>
<a href="javascript:void(0)" class="btn screen">Capture screen and save to the Gallery</a>
<a href="javascript:void(0)" class="btn viewport">Viewport snapshot returns fileURL</a>
<script>
function ready(callback) {
// Call directly if JSBridge has been injected
if (window.AlipayJSBridge) {
callback && callback();
} else {
// Monitor the injected events if JSBridge hasn't been injected
document.addEventListener('AlipayJSBridgeReady', callback, false);
}
}
ready(function() {
document.querySelector('.screen').addEventListener('click', function() {
AlipayJSBridge.call('snapshot', function(result) {
alert(JSON.stringify(result));
});
});
document.querySelector('.viewport').addEventListener('click', function() {
AlipayJSBridge.call('snapshot', {
range: 'viewport',
dataType: 'fileURL',
saveToGallery: false
}, function(result) {
alert(JSON.stringify(result));
});
});
});
</script>
API
AlipayJSBridge.call('snapshot', {
range, saveToGallery, dataType, imageFormat, quality,
maxWidth, maxHeight
}, fn)
Input parameters
Name | Type | Description | Required | Default value |
---|---|---|---|---|
range | String | Snapshot range: Screen: The whole screen of the current client Viewport: Visible area in the webpage Document: The entire webpage. Note: document captures all webpages. On Android, the browser memory will overflow if the webpage is too large, so please use Screen |
N | screen |
saveToGallery | bool | Whether or not to save to Gallery | N | true |
dataType | String | Result data format: dataURL: Base64-encoded image data fileURL: The URL of image in the file system (the image is stored in the temporary directory and will be cleared when you quit the App) none: No data is returned (for saving to the Gallery) |
N | none |
imageFormat | String | jpg / png | N | “jpg” |
quality | int | The quality of JPG image, with value from 1 to 100 | N | 75 |
maxWidth | int | The maximum width of image, which will be reduced by equal ratio if too large | N | Unlimited |
maxHeight | int | The maximum height of image, which will be reduced by equal ratio if too large | N | Unlimited |
fn | function | Callback function | N |
Output parameters
Parameter result brought in by the callback function: {success, fileUrl, dataURL}.
Name | Type | Description |
---|---|---|
success | bool | Whether the processing is successful |
fileUrl | String | The URL of image in the file system |
fileUrl | String | Base64-encoded image data |
Error code
Error code | Description |
---|---|
10 | Failed to save Gallery |
11 | Failed to save image file |