How to Use NPM goURL

WebTechRiser.com > Javascript > How to Use NPM goURL

goURL is a very small NPM package (developed by KingRayhan) that allows you to redirect any DOM element to a specific URL through a click event.

How to Install the Package

npm install gourl
// or
yarn add gourl

If you want, you can also add this functionality to your project through CDN.

<script src="https://unpkg.com/gourl" />

Include package to your project

require('gourl');

Now if you want to go to a specific link through a click event, you simply need to attach the data-href attribute to the DOM element.

Some Examples

<button data-href="https://www.google.com/">click</button>

<button data-href="https://www.google.in/" data-target="_blank">click</button>

<a href="#" data-href="https://www.facebook.com">facebook</a>

<input type="text" value="instagram" data-href="https://www.instagram.com" data-target="_blank">

<br> <br>

<span data-href="https://www.youtube.com" data-target="_blank">youtube</span>

Available attributes

data-hrefput your hyperlink here to go
data-targetput url target method. supported values _blank and _self (Default)
Also read:  Creating a Hamburger Menu: Hands-on Tutorial and Examples
Category Javascript
Tag:

Leave Your Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.