How to force fully download txt file on link?

Download file when clicking on the link (instead of navigating to the file): <a href=”https://stackoverflow.com/questions/21088376/test.txt” download>Click here</a> Download file and rename it to mytextdocument.txt: <a href=”https://stackoverflow.com/questions/21088376/test.txt” download=”mytextdocument”>Click here</a> The download attribute specifies that the target will be downloaded when a user clicks on the hyperlink. This attribute is only used if the href attribute is … Read more

How to use normal anchor links with react-router

The problem with anchor links is that react-router’s default is to use the hash in the URL to maintain state. Fortunately, you can swap out the default behaviour for something else, as per the Location documentation. In your case you’d probably want to try out “clean URLs” using the HistoryLocation object, which means react-router won’t … Read more

Convert clickable anchor tags to plain text in html document

You should be using DOM to parse HTML, not regular expressions… Edit: Updated code to do simple regex parsing on the href attribute value. Edit #2: Made the loop regressive so it can handle multiple replacements. $content=” <p><a href=”http://www.website.com”>This is a text link</a></p> <a href=”http://sitename.com/#foo”>bah</a> <a href=”#foo”>I wont change</a> “; $dom = new DOMDocument(); $dom->loadHTML($content); … Read more

Get anchor from URI

This isn’t possible as clients don’t send the “anchor part” to the server As an example, here’s the exact request that Chrome generated after submitting http://example.com/#foobar (recorded using Wireshark): GET / HTTP/1.1 Host: example.com Connection: keep-alive User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/532.3 (KHTML, like Gecko) Chrome/4.0.223.11 Safari/532.3 Cache-Control: max-age=0 Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Encoding: gzip,deflate … Read more

Override default behaviour for link (‘a’) objects in Javascript

If you don’t want to iterate over all your anchor elements, you can simply use event delegation, for example: document.onclick = function (e) { e = e || window.event; var element = e.target || e.srcElement; if (element.tagName == ‘A’) { someFunction(element.href); return false; // prevent default action and stop event propagation } }; Check the … Read more

tech