Re: conditional javascript script

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: MD Websunlimited (none_at_none.com)
Date: 02/28/04


Date: Sat, 28 Feb 2004 14:36:14 -0600

Steve,

That code will not work as the include needs to be process at the server and JavaScript is client side.

To accomplish create two script files that write out the code using document.write statements. Next, use the conditional JavaScript
source that was shown before to src the included script.

To recap you'd have two file of script:
vert_nav.js and hor_nav.js

Then the page would contain:

<script language="Javascript" type="text/javascript" >
if (screen.width <= 600) {
 document.write('<script src="side_nav/vert_nav.js" type="text/javascript" >');
    }
 else {
   document.write('<script src="side_nav/hor_nav.js" type="text/javascript" >\n');
 }
document.write('</script>');
</script>

In J-Bots we use a technique to allow browser independance while allowing ease of program. To accomplish this we use function
overlays that bring in code based upon the browser. This is the code that we use:

var oBrowser=new checkBrowser();

// load the browser specific code Why does this work?
if(oBrowser.ns4) {
  document.write("<script language=\"JavaScript1.2\" src=\"" + sWUScripts + "_WUScripts/ns4obj.js\" >\n</" + "script>");
} else {
 document.write("<script language=\"JavaScript\" src=\"" + sWUScripts + "_WUScripts/ieobj.js\" >\n</" + "script>");
}

if (oBrowser.ns5){
  document.write("<script language=\"JavaScript\" src=\"" + sWUScripts + "_WUScripts/ns5obj.js\" >\n</" + "script>");
}

HTH,

-- 
Mike -- FrontPage MVP '09 - '02
http://www.websunlimited.com
"Steve" <steve@nospamtnccreations.com> wrote in message news:euL46dh$DHA.2524@TK2MSFTNGP10.phx.gbl...
> Thanks for the responses, guys, unfortunately, I can't seem to get this
> stuff to do what I want. Maybe a bit more explanation will help.
>
> I am trying to set up this site so that it will pull different elements into
> a page based on screen resolution. For instance, I have two style sheets,
> one based on a screen resolution of 800 X 600, another one based on higher
> resolutions, to set text sizes and some other things. This is working well.
>
> Now I need to pull in navigational stuff again based on resolution. Nomally
> I would just use an include file to do this such as:
> <!-- Include file="something.htm" --> but in this instance I need to base it
> on screen resolution. And rather than an html file, I was trying to pull in
> the script instead. Since I can't seem to get that to work, I tried this
> instead:
>
>       <script language="Javascript" type="text/javascript">
>   if (screen.width <= 600) {
>    document.write('<!-- #Include file=side_nav/side_nav.html -->');
>    }
>    else {
>    document.write('<!-- #Include file=vert_nav1/vert_nav1.html -->');
>    }
>       </script>
>
> I believe I could do this pretty easily using ASP and VB, but in this
> instance, I would prefer to use javascript and html.
>
> However, although I do not get any script errors, this is not working. Am I
> simply trying to do something that is not possible?
>
> TIA
>
> Steve G
>
> "Steve" <steve@nospamtnccreations.com> wrote in message
> news:uHf1Cna$DHA.2660@TK2MSFTNGP10.phx.gbl...
> > Hi All...
> >
> > Got a question regarding javascript.
> >
> > I am trying to use javascript to call a navigational bar based on screen
> > resolution:
> >
> >       <script language="Javascript" type="text/javascript"
> >   if (screen.width <= 600) {
> >    src="side_nav/side_nav.js"
> >    }
> >     else {
> >     src="vert_nav1/vert_nav1.js"
> >     }>
> >       </script>
> >
> > This is not working...soooo...anyone got any ideas as to why? I sure would
> > appreciate some help here.
> >
> > TIA
> >
> > Steve G
> >
> >
>
>


Relevant Pages

  • Re: conditional javascript script
    ... Steve G ... Next, use the conditional JavaScript ... > source that was shown before to src the included script. ... >> a page based on screen resolution. ...
    (microsoft.public.frontpage.client)
  • Re: Calculate a Quality sheet
    ... :>how to Accomplish this??? ... Buy a book, or take a course in Java [the script, not the ... Realise that Java and Javascript are completely different ...
    (uk.education.maths)
  • VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help
    ... Job is to convert that JAVASCRIPT code into SIMPLE VBA code ... Here's a bookmarklet that will tell you whether or not the browser ... JS sends request to the server (to a PHP script) ... This is the PHP script. ...
    (microsoft.public.vb.controls.internet)
  • VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help
    ... Job is to convert that JAVASCRIPT code into SIMPLE VBA code ... Here's a bookmarklet that will tell you whether or not the browser ... JS sends request to the server (to a PHP script) ... This is the PHP script. ...
    (microsoft.public.inetsdk.programming.webbrowser_ctl)
  • VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted
    ... Job is to convert that JAVASCRIPT code into SIMPLE VBA code ... Here's a bookmarklet that will tell you whether or not the browser ... JS sends request to the server (to a PHP script) ... This is the PHP script. ...
    (microsoft.public.vb.6.webdevelopment)