0

My mailto hyperlinks don't fire correctly in both Chrome & Firefox, yet in Safari fire perfectly.

Can anyone see a conflict with the Onclick and Onblur rules I have?

    function saveText(){
    var xr = new XMLHttpRequest();
    var url = "saveNewText.php";
    var text = document.getElementById("editable").innerHTML;
    var vars = "newText="+text;
    xr.open ("POST", url, true)
    xr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xr.send(vars);
}


<div id="editable" onclick="listenForDoubleClick(this);" onblur="saveText(); this.contentEditable=false" contenteditable="false">Test Name
        <a href="mailto:test.name@website.com"></a>
</div>

As soon as you take these out of the equation; they fire perfectly fine in both browsers which is why I believe them to be the problem

  • Possible duplicate of [How to prevent page from jumping to top of page with mailto link in an anchor?](https://stackoverflow.com/questions/51171611/how-to-prevent-page-from-jumping-to-top-of-page-with-mailto-link-in-an-anchor) – Code_Ninja Jul 11 '18 at 11:06
  • check my answer in the above tagged link, I think that will solve your problem. – Code_Ninja Jul 11 '18 at 11:11
  • 1
    https://jsfiddle.net/ce13w610/4/ – Arpit Jain Jul 11 '18 at 11:26
  • @Code_Ninja thanks, that works however it then breaks my contentEditable script which saves the content to a sql database. Is there another work around in which it can be linked? Currently I have the div set to listen for a double click, which helps separate clicking to edit the div contents and also clicking on the email link – Frank Goodier Jul 11 '18 at 12:49
  • @ArpitJain this sorted it - many thanks! – Frank Goodier Jul 11 '18 at 13:34

0 Answers0