?
Solved

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

Posted on 2003-03-09
10
Medium Priority
?
740 Views
Last Modified: 2011-10-03
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 ...

BL
0
Comment
Question by:beni_luedi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 10

Accepted Solution

by:
kollegov earned 500 total points
ID: 8100636
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:
<form>
<input type="burron" value="back" onClick="history.go(-1); return false;">
<input type="burron" value="forward" onClick="history.go(1); return false;">
</form>

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.next) history.forward(); return false;">Forward</a>
But really there is no need to do this, no move will be done wheb no history esixsts

3.
<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.

0
 
LVL 5

Expert Comment

by:kasandra
ID: 8100798
> 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":
http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_11179591.html
0
 

Author Comment

by:beni_luedi
ID: 8100930
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?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:kollegov
ID: 8100940
Ooooopsss, I didn't realize question #3 completely

Well, something CAN be done :)
Try this

------------------------------
Hello
<style MEDIA='print'>
 .noprint {
   display:none;
 }
</style>

<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 :)
0
 

Author Comment

by:beni_luedi
ID: 8101493
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:

- BACK
- FORWARD
- PRINT
- CLOSE

The BACK and FORWARD buttons don't work. I believe it is because I use the window.open(...) 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 window.open(...) 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 ...

BL
0
 

Author Comment

by:beni_luedi
ID: 8101497
I will give more points for a useful answer.
0
 

Author Comment

by:beni_luedi
ID: 8101987
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.

BL
0
 

Expert Comment

by:RavenX30
ID: 8103198
how can your URL always be the same?

You talking about URL cloak? this still records history?
0
 

Author Comment

by:beni_luedi
ID: 8107110
Let's say my URL is ...

www.MyDomain.com/MyFolder/MyFile.asp

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 ...

window.open("www.MyDomain.com/MyFolder/MyFile.asp", ...)

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.
0
 
LVL 10

Expert Comment

by:kollegov
ID: 8108294
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 window.open(...) 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
like:
 
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 = window.open(.......)
  }
  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?
www.MyDomain.com/MyFolder/MyFile.asp
What does your ASP analyse ( referrer ?)

BTW, you can add dummy random parameter to avoid exacty SAME URLs :)
window.open("www.MyDomain.com/MyFolder/MyFile.asp?rnd="+Math.random(), ...)


0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question