0

I've used window.location (.assign, .replace, .href) to redirect to a page product on click. But for some reason it automatically changes some of href links.

For example: previous href="commercial/fonts/fonts.min.css" is now href="product/commercial/fonts/fonts.min.css".

previous HTML file

<link rel="stylesheet" type="text/css" href="commercial/fonts/fonts.min.css" />

After this click event triggers

$('.productImage').on('click', function(){
        var product_id = $(this).data('id');
        window.location.assign("/product/"+product_id);
});

New HTML

<link rel="stylesheet" type="text/css" href="product/commercial/fonts/fonts.min.css" />

Product is automatically to the href. This happens with some other files as well. In case of img src as well

Matthias Schmidt
  • 585
  • 1
  • 7
  • 25
rakesh shrestha
  • 1,335
  • 19
  • 37

1 Answers1

0

Use / at the beginning of your href, like so: href="commercial/fonts/fonts.min.css" - that should make the URL relative to your document root. At the moment you're using a URL that is relative to the current document. You may want to read up on absolute vs relative URLs, eg in this answer.

Matthias Schmidt
  • 585
  • 1
  • 7
  • 25