href = 'https://google.com'; }); If you load the page and click on the button, you will navigate to the webpage you assigned to the property. The location. href property returns a string containing the whole URL and allows the href to be updated.
The location (URL) of the object it is linked to. Changes done on it are reflected on the object it relates to. Both the Document and Window interface have such a linked Location, accessible via Document.
The Location. assign() method causes the window to load and display the document at the URL specified. After the navigation occurs, the user can navigate back to the page that called Location.
Window Location Href The window.location.href property returns the URL of the current page.
window.location
is of type Location
while .attr('data-href')
returns a string, so you have to assign it to window.location.href
which is of string type too. For that replace your following line:
window.location = $link.attr('data-href');
for this one:
window.location.href = $link.attr('data-href');
you have missed the href
:
Standard, To use window.location.href
as window.location
is technically an object containing:
Properties
hash
host
hostname
href <--- you need this
pathname (relative to the host)
port
protocol
search
try
window.location.href = $link.attr('data-href');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With