Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 742
  • Last Modified:

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

BL
0
beni_luedi
Asked:
beni_luedi
1 Solution
 
kollegovCommented:
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
 
kasandraCommented:
> 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
 
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?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
kollegovCommented:
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
 
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:

- 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
 
beni_luediAuthor Commented:
I will give more points for a useful answer.
0
 
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.

BL
0
 
RavenX30Commented:
how can your URL always be the same?

You talking about URL cloak? this still records history?
0
 
beni_luediAuthor Commented:
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
 
kollegovCommented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now