2

I'm experimenting with the jQuery UI tab control, and have three tabs that each load a different page through AJAX. The pages that are loaded are complete html-pages, with their own Javascript and CSS.

Scripts that are inline in the html body are ok, so are CSS in the style-attribute on tags, but Javascript and CSS in the head of the loaded pages are not used at all.

How can I make use of the Javascript and CSS in the head of the loaded pages? Or do I have to include all CSS and Javascript in the page containing the tab control?

2 Answers 2

1

The AJAX load is going to filter out anything that's not in the body element. You can put the CSS/Javascript tags in the body and they will be added to your page, but I would avoid that if at all possible. If you're not careful, you'll end up including things multiple times.

I suggest putting the common stuff like jQuery itself, plugins, etc. on the page containing the tabs and only put tab-specific scripts on the bits that are loaded via AJAX. You'll need to be careful to manage ids -- they have to be globally unique, not unique within the tab. Sticking with classes may be a better way to handle this or preface your ids with the tab name. For CSS I would try to make it so the CSS applies to the entire page, including tabs, and load it with the page.

YMMV.

Sign up to request clarification or add additional context in comments.

2 Comments

Seems to much of a hassle, I think I just continue working without the tab-control, and just use normal links between pages.
@Joachim - In practice I don't find it to be. It's probably easier to start this way that to retrofit something into tabs, but honestly I haven't had much trouble. Of course, ASP.NET MVC might make this easier than some other frameworks because of the separation of concerns.
0

You could add this line in your head:

<link rel="stylesheet" id="yourid" type="text/css" />

and this after your ajax call:

document.getElementById('yourid').href='css/'+yourvariable+'.css';}

And you can do the same for scripts (change rel and type).

Comments

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.