{"id":3467,"date":"2023-09-10T09:54:01","date_gmt":"2023-09-10T00:54:01","guid":{"rendered":"https:\/\/blue-bear.jp\/kb\/?p=3467"},"modified":"2023-09-10T09:54:02","modified_gmt":"2023-09-10T00:54:02","slug":"javascript%e7%94%bb%e5%83%8f%e3%82%92%e3%82%af%e3%83%aa%e3%83%83%e3%82%af%e3%81%99%e3%82%8b%e3%81%a8%e7%94%bb%e5%83%8f%e3%82%92%e3%83%80%e3%82%a6%e3%83%b3%e3%83%ad%e3%83%bc%e3%83%89%e3%81%99","status":"publish","type":"post","link":"https:\/\/blue-bear.jp\/kb\/javascript%e7%94%bb%e5%83%8f%e3%82%92%e3%82%af%e3%83%aa%e3%83%83%e3%82%af%e3%81%99%e3%82%8b%e3%81%a8%e7%94%bb%e5%83%8f%e3%82%92%e3%83%80%e3%82%a6%e3%83%b3%e3%83%ad%e3%83%bc%e3%83%89%e3%81%99\/","title":{"rendered":"[javascript]\u753b\u50cf\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u753b\u50cf\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>&lt;a href=\"#\" id=\"downloadLink\">\n  &lt;img src=\"image.jpg\" alt=\"Download\" id=\"downloadButton\">\n&lt;\/a><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Get the image element by its ID\nvar downloadButton = document.getElementById('downloadButton');\n\n\/\/ Function to extract filename from the image source URL\nfunction extractFilename(url) {\n    var segments = url.split('\/');\n    return segments.pop();\n}\n\n\/\/ Function to trigger the download with the extracted filename\nfunction downloadImage() {\n    \/\/ Extract the filename from the image source URL\n    var src = downloadButton.src;\n    var fileName = extractFilename(src);\n    \n    \/\/ Create an anchor element\n    var downloadLink = document.createElement('a');\n    \n    \/\/ Set the href attribute to the image source\n    downloadLink.href = src;\n    \n    \/\/ Set the download attribute to the extracted filename\n    downloadLink.download = fileName;\n    \n    \/\/ Simulate a click on the anchor element to trigger the download\n    downloadLink.click();\n}\n\n\/\/ Add a click event listener to the image to trigger the download\ndownloadButton.addEventListener('click', downloadImage);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/3467"}],"collection":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/comments?post=3467"}],"version-history":[{"count":1,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/3467\/revisions"}],"predecessor-version":[{"id":3468,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/3467\/revisions\/3468"}],"wp:attachment":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/media?parent=3467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/categories?post=3467"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/tags?post=3467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}