Turning Javascript off while printing

J

Jlcarroll

Hi,

I am building a web page.and have a simple javascript menu... I call
the javascript menu within a div block that my print sytlesheet has
set as a display: none;, well all the content in that block doesn't
show up, EXCEPT the javascript is still getting run...


<div class="menu">
<!--*****************These lines load in the
menu.***************************-->

<div id='MenuPos' style='position:relative; width:120; height:201;
margin-left:10px'>

<script type='text/javascript'>

//HV Menu v5- by Ger Versluis (http://www.burmees.nl/)

//Submitted to Dynamic Drive (http://www.dynamicdrive.com)

//Visit http://www.dynamicdrive.com for this script and more



function Go(){return}



</script>

<script type='text/javascript' src='/includes/jlc_menu.js'></script>

<script type='text/javascript' src='/includes/menu_com.js'></script>

<noscript>Your browser does not support script</noscript>
</div>

the stuff that doesn't show up when printing, just as it should....
<!-- *End menu*-->
</div>

Any idea how to fix this?

Thanks a bunch!
 
D

David Mark

Hi,

I am building a web page.and have a simple javascript menu... I call
the javascript menu within a div block that my print sytlesheet has
set as a display: none;, well all the content in that block doesn't
show up, EXCEPT the javascript is still getting run...

<div class="menu">
<!--*****************These lines load in the
menu.***************************-->

<div id='MenuPos' style='position:relative; width:120; height:201;
margin-left:10px'>

<script type='text/javascript'>

//HV Menu v5- by Ger Versluis (http://www.burmees.nl/)

//Submitted to Dynamic Drive (http://www.dynamicdrive.com)

Oh no.
//Visithttp://www.dynamicdrive.comfor this script and more

For the love of God, don't.
function Go(){return}

</script>

<script type='text/javascript' src='/includes/jlc_menu.js'></script>

<script type='text/javascript' src='/includes/menu_com.js'></script>

<noscript>Your browser does not support script</noscript>

Delete this. It serves no purpose. Better yet, write your menu
without script and then look for a non-invasive menu script.
</div>

the stuff that doesn't show up when printing, just as it should....
<!-- *End menu*-->
</div>

Any idea how to fix this?

The script is going to run regardless of the page's style. What's the
problem (besides the lousy script?) Is it making the menu show up
when the page loads?
 
J

Jlcarroll

oh, I guess that I wasn't clear... I want the script to run on the
screen display, but I want the print display to leave the menu off...
everything in the div block isn't displayed on print, EXCEPT this
bloody menu.

As for a "non-invasive" script... I did this YEARS ago, back before
css even existed... back then I was using tables to do the layout...
ugg ya..., and just finally got around to upgrading to css. But I
haven't gotten around to changing the menu script used... it has
worked fine for me until now. Although I am good at html, I must admit
that I don't know javascript at all, so I don't know what you mean by
invasive or non invasive scripts. Nor do I know how using a different
menu script would help me get it to not run when I am printing the
page.

I am sure that I am doing many things wrong, but I appreciate help
learning to do this right...

Thanks for your help,

James
 
D

David Mark

oh, I guess that I wasn't clear... I want the script to run on the
screen display, but I want the print display to leave the menu off...
everything in the div block isn't displayed on print, EXCEPT this
bloody menu.

That's because the bloody invasive menu is certainly setting its
display property to "block" and overriding the container's display
property of "none."
As for a "non-invasive" script... I did this YEARS ago, back before
css even existed... back then I was using tables to do the layout...
ugg ya..., and just finally got around to upgrading to css. But I
haven't gotten around to changing the menu script used... it has
worked fine for me until now. Although I am good at html, I must admit
that I don't know javascript at all, so I don't know what you mean by
invasive or non invasive scripts. Nor do I know how using a different
menu script would help me get it to not run when I am printing the
page.

I am sure that I am doing many things wrong, but I appreciate help
learning to do this right...

First, turn off scripting in your browser and view the page. I am
sure you will see that instead of a menu, the user sees that silly
noscript message. That's not what you want. Whatever elements (list
items probably) the menu script is adding to the document should be
there in the first place so that users without script can use the
menu. Write the menu so it works without scripting and then find a
script that attaches listeners to the existing elements to show and
hide them as desired. Your printing problem will go away as well.
 
J

Jlcarroll

First, turn off scripting in your browser and view the page. I am
sure you will see that instead of a menu, the user sees that silly
noscript message. That's not what you want.

I knew about this, but it wasn't my first concern... most browsers
support script, and most users turn it on because they have no idea
how to turn it off, and it comes on... Of course you are right, but
most important bug first. I never said this page was perfect, it is
designed for use by a few family members and friends, all of which
have javascripting on, so for my target audience this is a non-issue.
If I was designing a professional page perhaps.
Whatever elements (list
items probably) the menu script is adding to the document should be
there in the first place so that users without script can use the
menu. Write the menu so it works without scripting and then find a
script that attaches listeners to the existing elements to show and
hide them as desired. Your printing problem will go away as well.

This is an interesting suggestion, and I think that I know just enough
about javascript to understand what you have in mind, but not enough
to write it. I am using someone else's menu because I don't know
javascript well, there is a reason that I didn't write my own.

Since I do know how to program in other languages rather well, I could
just buckle down and learn another langue, and that it wouldn't take
too much time, which may be what I have to do, but given that I have
to write a midterm tomorrow, and grade a bunch of tests, this likely
won't happen in the next day or so.

As a temporary fix, I was really hoping for a simple

if printing ___ if not printing ____

sort of thing. Does such a command exist?

James
 
D

David Mark

I knew about this, but it wasn't my first concern... most browsers
support script, and most users turn it on because they have no idea
how to turn it off, and it comes on... Of course you are right, but
most important bug first. I never said this page was perfect, it is
designed for use by a few family members and friends, all of which
have javascripting on, so for my target audience this is a non-issue.
If I was designing a professional page perhaps.


This is an interesting suggestion, and I think that I know just enough
about javascript to understand what you have in mind, but not enough
to write it. I am using someone else's menu because I don't know
javascript well, there is a reason that I didn't write my own.

Since I do know how to program in other languages rather well, I could
just buckle down and learn another langue, and that it wouldn't

You can still use a canned menu script, there are plenty out there
that work as I described. Granted there are a lot more that work like
the one you have now.

take
too much time, which may be what I have to do, but given that I have
to write a midterm tomorrow, and grade a bunch of tests, this likely
won't happen in the next day or so.

As a temporary fix, I was really hoping for a simple

if printing ___ if not printing ____

No.
 
R

rbevers

Hi,

I am building a web page.and have a simple javascript menu... I call
the javascript menu within a div block that my print sytlesheet has
set as a display: none;, well all the content in that block doesn't
show up, EXCEPT the javascript is still getting run...

<div class="menu">
<!--*****************These lines load in the
menu.***************************-->

<div id='MenuPos' style='position:relative; width:120; height:201;
margin-left:10px'>

<script type='text/javascript'>

//HV Menu v5- by Ger Versluis (http://www.burmees.nl/)

//Submitted to Dynamic Drive (http://www.dynamicdrive.com)

//Visithttp://www.dynamicdrive.comfor this script and more

function Go(){return}

</script>

<script type='text/javascript' src='/includes/jlc_menu.js'></script>

<script type='text/javascript' src='/includes/menu_com.js'></script>

<noscript>Your browser does not support script</noscript>
</div>

the stuff that doesn't show up when printing, just as it should....
<!-- *End menu*-->
</div>

Any idea how to fix this?

Thanks a bunch!


The best way to do it is with css. Like this:

<style type="text/css" media=print>
..menuBar{display:none;}
</style>

<style type="text/css">
..menuBar{font-family:Arial;
//all of the rest of the style for your menuBar}
</style>

when you declare the first div for your menu <div class=menuBar>

When sent to the printer, it will see the media is "print" and make
the menu invisable

I hope this helps. I do it on all of my web sites
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top