Skip to content Skip to sidebar Skip to footer

Onclick Js Event On A Image Map?

I have been searching for hours for an answer here at stackoverflow and in the web. However all the answers I tried didn't work for me. Basically, I would like to put an onclick ev

Solution 1:

I removed downloadLink.onclick = destroyClickedElement; and added document.body.removeChild(downloadLink); at the end. So when you press button and download file, the hidden link is destroyed. (Works in Chrome)

UPDATE: (now works in Firefox locally or on JSFiddle - stackoverflow codesnippet still doesn't work) In area tag I removed onclick="txtdownload()" and changed href="#" to href="javascript:txtdownload()". JSFiddle: https://jsfiddle.net/00bk1zad/2/

For future, you can use FileSaver.js. Check this link with examples: https://github.com/eligrey/FileSaver.js/

functiontxtdownload() {
	var textToSave = document.getElementById("editor").value;
  var textToSaveAsBlob = newBlob(
    [textToSave],
    {type:"application/msword"});
  var textToSaveAsURL = window.URL.createObjectURL(textToSaveAsBlob);
  var fileNameToSaveAs = "YouKtub.doc";
  var downloadLink = document.createElement("a");
  downloadLink.download = fileNameToSaveAs;
  downloadLink.innerHTML = "Download File";
  downloadLink.href = textToSaveAsURL;
  downloadLink.style.display = "none";
  document.body.appendChild(downloadLink);
  downloadLink.click();
  document.body.removeChild(downloadLink);
 }
<divalign=center><textareaid="editor"wrap="PHYSICAL"name="q"rows="9"></textarea></div><div><imgsrc="https://image.ibb.co/eYKuFc/img.jpg"usemap="#map1Map"border=0></div><mapname=map1Map><areacoords="268,46,47,113"href="javascript:txtdownload()"></map>

Post a Comment for "Onclick Js Event On A Image Map?"