Web Tools #548 - URL.canParse(), Web Frameworks, Git/CLI Tools, Vue Tools
source link: https://mailchi.mp/webtoolsweekly/web-tools-548
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
URL.canParse(), Web Frameworks, Git/CLI Tools, Vue Tools
|
Issue #548 • January 18, 2024
Advertisement
|
Build with the Power of Code — Without Writing Any Take control of HTML, CSS, and JavaScript in a visual canvas. Webflow generates clean, semantic code that’s ready to publish or hand to developers. |
In case you didn't know, there's a URL interface that exposes a number of different properties and methods for dealing with URLs in the browser. One relatively new method that now has almost cross-browser support in all modern browsers is the URL.canParse() method.
Notice the middle two lines are both checking a relative URL. But only the second one returns true because the first one doesn't provide a base. The last line checks an object (in this case a reference to an anchor element on the page). This assumes there is at least one anchor element present, otherwise it would return false.
You can try out my examples in this CodePen demo, which has al link on the page to ensure the fourth line works as expected. |
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK