0

I am working on a shopping cart on Netsuite coded with nested tables... I know it sucks.

Because I only have access to fields to customize the website I need a JS snippet to be able to load a specific CSS file for the shopping cart (to avoid styling the rest of the website)

I have never done that before, here is how I would start:

<script type="text/javascript">
var path = window.location.pathname;
if(path.indexOf('/Cart') !=-1 {
  // load css file
}
</script>

What code would do that for me?

1
  • 1
    Would a document.write work? document.write('<link rel="stylesheet" type="text/css" href="style.css">'); Commented Aug 21, 2015 at 23:57

2 Answers 2

3

Aside from closing your if(... with a ), this should get you going:

var styles = document.createElement("link");
styles.rel = "stylesheet";
styles.type = "text/css";
styles.href = "file.css";  // your file's URL
document.getElementsByTagName("head")[0].appendChild(styles);
Sign up to request clarification or add additional context in comments.

2 Comments

Awesome! Works perfectly! Thank you!
@user883356 great glad to help :) you should hit the little checkmark to accept the answer too if you don't mind ;)
0

While testing the url does work there is a better way to add tab and category specific markup.

In your website theme in the "Additions to Head" section add a tag <TAB_ADDONS> and add that to the site builder Tags but with a blank body

Then go to your list of tabs and find the shopping cart tab. Edit it and select Tag Overrides find TAB_ADDONS and enter:

<link rel="stylesheet" type="text/css" href="file.css">

you'd use the root relative url for the href.

This keeps your theme much cleaner and allows arbitrary code inclusions.

1 Comment

Thanks for your answer, it does sound like it is really how Netsuite work, i will try this on Monday. Also, if you have any advice, thoughts on how to style the whole shopping car/account/checkout in Site Builder (not the advanced) i will be really interested! Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.