How can I make a clickable link in an NSAttributedString?

Use NSMutableAttributedString. NSMutableAttributedString * str = [[NSMutableAttributedString alloc] initWithString:@”Google”]; [str addAttribute: NSLinkAttributeName value: @”http://www.google.com” range: NSMakeRange(0, str.length)]; yourTextView.attributedText = str; Edit: This is not directly about the question but just to clarify, UITextField and UILabel does not support opening URLs. If you want to use UILabel with links you can check TTTAttributedLabel. Also you should … Read more

jQuery disable a link

$(‘#myLink’).click(function(e) { e.preventDefault(); //do other stuff when a click happens }); That will prevent the default behaviour of a hyperlink, which is to visit the specified href. From the jQuery tutorial: For click and most other events, you can prevent the default behaviour – here, following the link to jquery.com – by calling event.preventDefault() in … Read more

What is href=”#” and why is it used?

About hyperlinks: The main use of anchor tags – <a></a> – is as hyperlinks. That basically means that they take you somewhere. Hyperlinks require the href property, because it specifies a location. Hash: A hash – # within a hyperlink specifies an html element id to which the window should be scrolled. href=”#some-id” would scroll … Read more

Google Apps Script to open a URL

This function opens a URL without requiring additional user interaction. /** * Open a URL in a new tab. */ function openUrl( url ){ var html = HtmlService.createHtmlOutput(‘<html><script>’ +’window.close = function(){window.setTimeout(function(){google.script.host.close()},9)};’ +’var a = document.createElement(“a”); a.href=”‘+url+'”; a.target=”_blank”;’ +’if(document.createEvent){‘ +’ var event=document.createEvent(“MouseEvents”);’ +’ if(navigator.userAgent.toLowerCase().indexOf(“firefox”)>-1){window.document.body.append(a)}’ +’ event.initEvent(“click”,true,true); a.dispatchEvent(event);’ +’}else{ a.click() }’ +’close();’ +'</script>’ // Offer URL as … Read more

Smooth scrolling when clicking an anchor link

Update April 2018: There’s now a native way to do this: document.querySelectorAll(‘a[href^=”#”]’).forEach(anchor => { anchor.addEventListener(‘click’, function (e) { e.preventDefault(); document.querySelector(this.getAttribute(‘href’)).scrollIntoView({ behavior: ‘smooth’ }); }); }); This is currently only supported in the most bleeding edge browsers. For older browser support, you can use this jQuery technique: $(document).on(‘click’, ‘a[href^=”#”]’, function (event) { event.preventDefault(); $(‘html, body’).animate({ scrollTop: … Read more

retrieve links from web page using python and BeautifulSoup [closed]

Here’s a short snippet using the SoupStrainer class in BeautifulSoup: import httplib2 from bs4 import BeautifulSoup, SoupStrainer http = httplib2.Http() status, response = http.request(‘http://www.nytimes.com’) for link in BeautifulSoup(response, parse_only=SoupStrainer(‘a’)): if link.has_attr(‘href’): print(link[‘href’]) The BeautifulSoup documentation is actually quite good, and covers a number of typical scenarios: https://www.crummy.com/software/BeautifulSoup/bs4/doc/ Edit: Note that I used the SoupStrainer class … Read more

How to change the href attribute for a hyperlink using jQuery

Using $(“a”).attr(“href”, “http://www.google.com/”) will modify the href of all hyperlinks to point to Google. You probably want a somewhat more refined selector though. For instance, if you have a mix of link source (hyperlink) and link target (a.k.a. “anchor”) anchor tags: <a name=”MyLinks”></a> <a href=”http://www.codeproject.com/”>The CodeProject</a> …Then you probably don’t want to accidentally add href … Read more