Major indices closed on Friday, holding near record highs as both the S&P 500 and Nasdaq managed to notch a third straight weekly gain.