Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Tony 23
808 PointsHow can I build a Javascript Url Parser using Regular Expressions?
The Javascript parser has to find all the urls in the text and open them in a new browser tab when get clicked at the button. I came up with this regular expression: ((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?) that finds the URLs I just can't quite understand how I will connect it to my function. Your feedback would be greatly appreciated!!
1 Answer
Clayton Perszyk
Treehouse Moderator 49,057 PointsNot sure this is what you're looking for, but you could use the following in your function to open a url in a new tab:
window.open('https://www.teamtreehouse.com', '_blank');
Just change out the url for your own. You can also pass in a variable that has a url string value.
Tony 23
808 PointsTony 23
808 PointsThanks a lot Clayton. I want to build a form, that once u type a random text with url links inside it and press the submit button, it takes the url links from the text and opens it in a new tab.