> From: Code for Libraries [mailto:[log in to unmask]] On
> Behalf Of Vishwam Annam
> Sent: 08 June, 2005 14:41
> To: [log in to unmask]
> Subject: [CODE4LIB] Javascript question
>
> I have a question about including html files in javascript. I
> created a page at
> http://www.libraries.wright.edu/services/copyright/fac_staff/p
> rimary.html?Faculty
> where I am passing value via url as "?Faculty", and I wrote
> javascript such as below:
>
> <script type="text/javascript">
> a=location.search.substring(1);
> if(a=="Faculty")
> {
> document.write(' I want to include faculty.html file here'); } else
> if(a=="Students")
> {
> document.write('I want to include students.html file here');
> } </script>
>
> Is there anyway I can do this with Javascript? I'd appreciate
> your responses,
What is the intent of doing this? If you are trying to have
two separate documents, one for faculty and the other for
students, then just place the content in two documents. For
example:
primary.html
primary-faculty.html
primary-student.html
in primary.html you could just do:
<script type="text/javascript">
a = location.search.substring(1);
if (a.toLowerCase() == "Faculty".toLowerCase())
window.location.href = primary-faculty.html;
else
window.location.href = primary-student.html;
</script>
but this still begs the question: why not just have your users go
directly to primary-faculty.html or primary-student.html? The only
reason I can see, is when primary.html is a well known URL on your
site and you don't want to change it. If that's the case, you could
have your Web server just rewrite the URL's:
primary.html?Faculty -> primary-faculty.html
primary.html?Student -> primary-student.html
The only other reason why you might want to do this sort of thing,
is if you have one page and you want to include additional content
for either faculty or students. In that case, why not just use an
iframe? For example:
<script type="text/javascript">
ifrm = document.getElementById("ifrm");
a = location.search.substring(1);
if (a.toLowerCase() == "Faculty".toLowerCase())
ifrm.src = primary-faculty.html;
else
ifrm.src = primary-student.html;
</script>
Andy.
|