Picture Box download image

Hoping someone can shed some light on this - I’m using the following code to download the image I’ve created in a picturebox

Function downloadButton_onclick()
  Dim a
  PictureBox1.toDataURL()
  a=document.createElement("a")
  a.href = PictureBox1.toDataURL()
  a.download = "mypic.png"
  a.click()
End Function

This works for Google Chrome and Safari but does nothing in Firefox.
Any thoughts?

Okay, sloppy coding. I needed to add

document.body.appendChild(a)

So the code looks like this:

Function downloadButton_onclick()
  Dim a
  PictureBox1.toDataURL()
  a=document.createElement("a")
  document.body.appendChild(a)
  a.href = PictureBox1.toDataURL()
  a.download = "mypic.png"
  a.click()
End Function

Good if someone would like to download the PictureBox contents.