1

I need some Javascript help as I'm not very good at it. I'm trying to redirect a breadcrumb link when clicked:

<a href="/tiles" class="ProductItem-nav-breadcrumb-link">Tiles</a>

I've tried this;

<script type="text/javascript">
  document.getElementsByClassName(ProductItem-nav-breadcrumb-link).onclick = function () {
        location.href = "newURL";
    };
</script>

and this;

<script type="text/javascript">
  document.querySelector('.ProductItem-nav-breadcrumb-link').onclick = function () {
        location.href = "newURL";
    };
</script>

Neither of these worked. Does someone have a better solution?

Thanks

  • It's explained really well here: https://stackoverflow.com/questions/8454510/open-url-in-same-window-and-in-same-tab – Rendolph Feb 22 '21 at 21:48

1 Answers1

0

You can try:

window.location.href = 'https://example.com/';

or

 document.location.href = 'https://example.com/';

Booth examples should work.

Onlime
  • 26
  • 4