Move to previous / next page and print parts of a page

Hi experts,

I have 2 buttons that should work the same way like the BACK and FORWARD buttons on the toolbar.

1. What is the code?
2. Can I disable the button if there is no previous / next page? How can I check this?
3. I would like to print the document. How can I prevent parts of a page to be printed? That is probably a tag or a property of a tag.

Thanks ...

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

1. Back/forward links
<a href="javascript:void(0)" onClick="history.back(); return false;">BACK</a>
<a href="javascript:void(0)" onClick="history.forward(); return false;">Forward</a>
or the same
<a href="javascript:void(0)" onClick="history.go(-1); return false;">BACK</a>
<a href="javascript:void(0)" onClick="history.go(1); return false;">Forward</a>

You can do the same with form buttons:
<input type="burron" value="back" onClick="history.go(-1); return false;">
<input type="burron" value="forward" onClick="history.go(1); return false;">

2. To check previous or next exists you can do something like this.
<a href="javascript:void(0)" onClick="if(history.previous) history.back(); return false;">BACK</a>
<a href="javascript:void(0)" onClick="if( history.forward(); return false;">Forward</a>
But really there is no need to do this, no move will be done wheb no history esixsts

<a href="javascript:void(0)" onClick="window.print(); return false;">Print this page</a>

P.S. do not forget to return false from onClick to prevent browaser attempts to follow href link
after lick.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
> P.S. do not forget to return false from onClick to prevent > browaser attempts to follow href link
> after lick.

... or you can just put the javascript in the href:

<a href="javascript:history.back();">Back</a>
<a href="javascript:history.forward();">Forward</a>

<a href="javascript:window.print();">Print this page</a>

The window.print() will just bring up the printer dialog box, same as clicking the print button on the browser.  There have been a lot of posts to EE regarding controlling printing using JavaScript. The short answer is JavaScript doesn't give you much control - printing is handled by the browser. You might need to use ActiveX to do what you want.

Another question which asked if you can only print part of an HTML page was answered with "it can't be done":
beni_luediAuthor Commented:
So there is no way to use a tag or any other way to avoid printing the previous / next / print buttons that are visible on all pages?
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Ooooopsss, I didn't realize question #3 completely

Well, something CAN be done :)
Try this

<style MEDIA='print'>
 .noprint {

<div class="noprint">abc</div>
<a href="javascript:window.print()">Print</a>

Of course this is not supported by old  browsers
But MIE5+ and NN6+  handle this OK :)
beni_luediAuthor Commented:
Hi experts,

Thanks to all that answered so far. It doesn't work yet, but I believe it is my fault. I try to explain what I want to do:

My popup window should display a helpfile. It should work the same way like helpfiles for apps (like word, access, ...). I use a asp page to generate the content.

The popup window has the following buttons:


The BACK and FORWARD buttons don't work. I believe it is because I use the command whenever content of the popup window has to be changed by the "Main page" even if the popup window is already opened. The name of the window is simply called "help".

a) With which command can I replace the command, in case the window is already opened?
b) How can I refer to the popup window in JavaScript and check if it is opened?
c) How can I make the popup window load a certain url?

I hope you understand. Thanks again ...

beni_luediAuthor Commented:
I will give more points for a useful answer.
beni_luediAuthor Commented:
OK. I think I was right with my theory.

The page's URL was always the same, so IE only refreshed the already displayed page. Therefore no history and furthermore no way to go back.

NN displayed it the right way, but also had no history neighter.

I use now QueryString within the address. Now I get history entries and my buttons work correctly.

Thanks for your answers anyway.

how can your URL always be the same?

You talking about URL cloak? this still records history?
beni_luediAuthor Commented:
Let's say my URL is ...

So this URL will always be the same. Whenever I call it. Yes sure, you're thinking now. My problem was, when I called my popup window with ..."", ...)

and the URL was exactly the same then I had the above described problem. No history in IE and NN, and furthermore IE didn't even display the new dynamic content, but just simply refreshed the page.

So, my BACK and FORWARD buttons didn't work.
I think you are mistaken....

What happens in your case, You open popup from main page once
On other page you re-open popup with and I guess this clear history of popup window.

In order to avoid this effect you would need to store somewhere reference to once opened window.
As you may reload main page  then you would need some 'static' frame where to store variable with window reference.
So you need frameset with hidden frame (zero size frame) or if you already have frameset, then you can use
any frame you do not reload.  Just make variable there
var mywin=null;

Then in main frame you may do something like

function risePopup() {
   if(top.frames['someframe'].mywin==null  || top.frames['someframe'].mywin.closed)  {
        // rise new popup
         top.frames['someframe'].mywin =
  else {
        // popup exists and not closed
        top.frames['someframe'].mywin.location = 'popup.html'

In this case history wouldn't be cleared Doesn't matter when URL is the same, it create history entry
for document anyway.

Of course when popup will be closed once, history will be destroyed.

What I do not know is how your popup have different content when URL is the same and no parameters passed to asp?
What does your ASP analyse ( referrer ?)

BTW, you can add dummy random parameter to avoid exacty SAME URLs :)""+Math.random(), ...)

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.