screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Image Downloader</title> </head> <body> <h1>Javascript Download Image From URL</h1> <input type="text" id="imageUrl" placeholder="Enter Image URL"> <button onclick="downloadImage()">Download Image</button> <script> function downloadImage() { const imageUrlInput = document.getElementById('imageUrl'); const imageUrl = imageUrlInput.value; if (imageUrl) { fetch(imageUrl) .then(response => response.blob()) .then(blob => { const urlObject = window.URL || window.webkitURL || window; const imageUrl = urlObject.createObjectURL(blob); const a = document.createElement('a'); a.href = imageUrl; a.download = 'downloaded_image'; document.body.appendChild(a); a.click(); document.body.removeChild(a); }) .catch(error => console.error('Image download failed:', error)); } else { alert('Please enter a valid image URL'); } } </script> <style> body { font-family: Arial, sans-serif; background-color: #f4f4f4; text-align: center; padding: 20px; margin: 0 auto; } h1 { color: #333; } input { padding: 10px; margin: 10px; width: 300px; border: 1px solid #ccc; border-radius: 5px; } button { padding: 10px 20px; background-color: #4caf50; color: #fff; border: none; border-radius: 5px; cursor: pointer; font-size: 16px; } button:hover { background-color: #45a049; } </style> </body> </html>