Variable Visions

NetSuite category to product jQuery redirect

Published Thu. Mar. 21, 2013

I tired window.location, window.navigate, self.location but none seemed to work. I'm thinking NetSuite was using conflicting javascript.

While working on a NetSuite ecommerce site, we wanted to set up functionality that when a category only had ONE product, it would automatically redirect to the product page to avoid apparent redundancy with first and second level categories. Other systems contain similar functionality, but NetSuite does not by default.

In a previous article, I compare server side and client side redirects. And the different types of each. Since NetSuite sites are on JSP, I could not use Aphace rewrites, nor PHP header redirects. I thought that an html meta redirect would do the trick, but when I applied it to the head of the category in question, apparently NetSuite has products inherit scripts in the parent cateogires head tag. So the redirect just kept looping.

I then tried the javascript redirect approach. I tired window.location, window.navigate, self.location but none seemed to work. I'm thinking NetSuite was using conflicting javascript.

But, I was able to get a jQuery redirect working. I've already had jQuery loaded for other things, so I decided to use it. Although, one should differently learn old school js first and avoid jQuery if you can code without the library calls.

So, document.location.href worked like a charm when placed within any field in the NetSuite category. I placed mine at the top of the Detailed Description.

 

<script type="text/javascript">   
     document.location.href='http://www.url.com';
</script>

 

I urge you to learn all the server and client side redirects because they all have their place in your code belt.

Keywords:jQuery document.location.href redirect, client side redirects, server side redirects, window.location, window.navigate, self.location,