0

When I use the following script to get the link, the href starting with "#" will automatically add a prefix. How to avoid it?

document.addEventListener('mousemove', function (event)
{
    let elem = event.target;
    let jsonObject =
    {
        Key: 'mousemove',
        Value: elem.href
    };
    window.chrome.webview.postMessage(jsonObject);
});

Also, how to handle the case where "#" is in the middle of the text.

<p>Test:</p>

<ul>
  <li><a href="https://example.com">Website</a></li>
  <li><a href="mailto:test@example.com">Email</a></li>
  <li><a href="tel:+123456789">Phone</a></li>
  <li><a href="#ted.test@micr#osoft.com">Test #</a></li>
  <li><a href="Test#Test">Test # 2</a></li>
</ul>

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
大陸北方網友
  • 3,696
  • 3
  • 12
  • 37

0 Answers0