This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > Front Page > February 2004 > conditional javascript script
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
conditional javascript script
|
|
| Steve 2004-02-27, 11:28 pm |
| 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
| |
| Peter Taurins 2004-02-28, 5:28 am |
| You'll probably find that the variable only exists inside your script.
So, you'll need to document.write the naviagtion inside the script rather
than set the variable src and try it use it outside the script.
"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
>
>
| |
| MD Websunlimited 2004-02-28, 9:28 am |
| Hi Steve,
Assuming that "src" is as var then you can write the include out
document.write('<script src="' + src + '" type=text/javascript >');
--
Mike -- FrontPage MVP '97-'02
http://www.websunlimited.com
Need to protect your web pages Page Protector Pro
http://www.websunlimited.com/order/...Pro/pagepro.htm
FrontPage Add-ins Since '97 2003 / 2002 / 2000 Compatible
"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
>
>
| |
| Steve 2004-02-28, 12:28 pm |
| 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
>
>
| |
| Thomas A. Rowe 2004-02-28, 1:28 pm |
| In order to use the #Include, the page must be either .asp or .shtml, etc.,
second the #Include is a server-side statement and must be executed on the
server before the page is sent to the browser, not client-side, so it will
never work in JavaScript.
--
==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
WEBMASTER Resources(tm)
http://www.ycoln-resources.com
FrontPage Resources, WebCircle,
MS KB Quick Links, etc.
==============================================
To assist you in getting the best answers for FrontPage support see:
http://www.net-sites.com/sitebuilder/newsgroups.asp
"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...
would[color=darkred]
>
>
| |
|
| Thanks Thomas...I "think" I knew that <G> is there a javascript equivalent
to all of this?
Steve
"Thomas A. Rowe" <tarowe@mvps.org> wrote in message
news:O$HEjkh$DHA.3352@TK2MSFTNGP09.phx.gbl...
> In order to use the #Include, the page must be either .asp or .shtml,
etc.,
> second the #Include is a server-side statement and must be executed on the
> server before the page is sent to the browser, not client-side, so it will
> never work in JavaScript.
>
> --
>
> ==============================================
> Thomas A. Rowe (Microsoft MVP - FrontPage)
> WEBMASTER Resources(tm)
> http://www.ycoln-resources.com
> FrontPage Resources, WebCircle,
> MS KB Quick Links, etc.
> ==============================================
> To assist you in getting the best answers for FrontPage support see:
> http://www.net-sites.com/sitebuilder/newsgroups.asp
>
> "Steve" <steve@nospamtnccreations.com> wrote in message
> news:euL46dh$DHA.2524@TK2MSFTNGP10.phx.gbl...
> into
sheets,[color=darkred]
higher[color=darkred]
> well.
> Nomally
base[color=darkred]
> it
> in
Am[color=darkred]
> I
screen[color=darkred]
> would
>
>
| |
| Thomas A. Rowe 2004-02-28, 4:28 pm |
| I am not aware of any.
--
==============================================
Thomas A. Rowe (Microsoft MVP - FrontPage)
WEBMASTER Resources(tm)
http://www.ycoln-resources.com
FrontPage Resources, WebCircle,
MS KB Quick Links, etc.
==============================================
To assist you in getting the best answers for FrontPage support see:
http://www.net-sites.com/sitebuilder/newsgroups.asp
"Steve" <steve@nospamtnccreations.com> wrote in message
news:OYHHa1h$DHA.4028@tk2msftngp13.phx.gbl...
> Thanks Thomas...I "think" I knew that <G> is there a javascript equivalent
> to all of this?
>
> Steve
>
> "Thomas A. Rowe" <tarowe@mvps.org> wrote in message
> news:O$HEjkh$DHA.3352@TK2MSFTNGP09.phx.gbl...
> etc.,
the[color=darkred]
will[color=darkred]
this[color=darkred]
elements[color=darkred]
> sheets,
> higher
> base
pull[color=darkred]
this[color=darkred]
> Am
> screen
>
>
| |
| MD Websunlimited 2004-02-28, 5:28 pm |
| 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...
>
>
| |
|
| Thanks Mike..this is a big help
Steve G
"MD Websunlimited" <none@none.com> wrote in message
news:OqTqEqj$DHA.3712@tk2msftngp13.phx.gbl...
> 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...
into[color=darkred]
sheets,[color=darkred]
higher[color=darkred]
well.[color=darkred]
Nomally[color=darkred]
base it[color=darkred]
in[color=darkred]
Am I[color=darkred]
screen[color=darkred]
would[color=darkred]
>
>
| |
| MD Websunlimited 2004-02-28, 6:29 pm |
| Steve,
On thing that may help in your efforts here is to create a variable to hold the HTML, eg,
<script>
HTML='test test test';
HTML +='test1 test1 test1';
HTML +='test2 test2';
document.write(HTML);
</script>
Use F&R to replace any single quote in the HTML with an escaped single quote '
Use a RegEx to add the HTML += ' begining of the line and '; to the end of the line.
--
Mike -- FrontPage MVP '97-'02
http://www.websunlimited.com
Stop Spam Email Mining from your web pages with SpamStopper
http://www.websunlimited.com/order/...er_help_dir.htm
FrontPage Add-ins Since '97 2003 / 2002 / 2000 Compatible
"Steve" <steve@nospamtnccreations.com> wrote in message news:OAA$l5j$DHA.2512@TK2MSFTNGP11.phx.gbl...
> Thanks Mike..this is a big help
>
> Steve G
>
> "MD Websunlimited" <none@none.com> wrote in message
> news:OqTqEqj$DHA.3712@tk2msftngp13.phx.gbl...
> and JavaScript is client side.
> document.write statements. Next, use the conditional JavaScript
> type="text/javascript" >\n');
> ease of program. To accomplish this we use function
> we use:
> + "_WUScripts/ns4obj.js\" >\n</" + "script>");
> "_WUScripts/ieobj.js\" >\n</" + "script>");
> "_WUScripts/ns5obj.js\" >\n</" + "script>");
> news:euL46dh$DHA.2524@TK2MSFTNGP10.phx.gbl...
> into
> sheets,
> higher
> well.
> Nomally
> base it
> in
> Am I
> screen
> would
>
>
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|