Click to See Complete Forum and Search --> : How to get rid of previous window size and position on a new one?


Valery
01-24-2003, 01:11 PM
Hello All,

please help me solve a small problem...


I use a simple JavaScript for opening, resizing and positioning of a new window.

The script goes like this:

<SCRIPT LANGUAGE="javascript">
<!--
function
{
OpenWindow=window.open ("", "newwindow", "height=400,
width=470, toolbar=no, menubar=no, scrollbars=yes, resizable=yes,
location=no, directories=no, status=no")
}
-->
</SCRIPT>


The link to the new window looks like this:

<a href="secondary_page.html" target="_blank" onClick="window.open(this.href, 'secondary_page', 'width=470, height=400, left=100, top=100, screenX=100, screenY=100, scrollbars=yes, resizable=yes'); return false">Go to secondary page</a>


At the bottom of the new ("secondary") page there is either a normal "Close window" button

<FORM onSubmit="self.close();return false">
<INPUT TYPE=SUBMIT VALUE="Close window">
</FORM>

or a text command:

<div align="center"><a href="javascript:window.close();">Close window</a>


Now... If I want people - after they have viewed the secondary page - to return to the primary page, they just click on the "Close window" button or the text command above and they're back there where they came from and everything is just fine.

If, however, the secondary page (it was resized, remember?) was the entry page to which a visitor came through a search engine and he/she presses the "Close window" button, they're just nowhere...

Or, in such case, if I want to redirect that visitor to the "parent page" (the page he/she should have actually come from) and use a normal link like this:

<a href="primary_page.html">Close window</a>

instead of "Close window" button, then the parent page opens up resized and unnecessary positioned, i.e. repeating the size and position of the "secondary page" the visitor has just left...


I have also tried to use a "link button" like this:

<input type="button" value="Close Window" onclick="location='primary_page.html'">

instead of "Close window" button but, alas, to no avail - the "parent page" opens up resized and positioned as well...


Please excuse me for such a long explanation of my problem...

So the actual question is this:

If I have a resized and positioned window being the first window viewed, and I want people to both leave that page by clicking on the "Close window" button AND (on the same click!) redirect them to the "parent page", how do I get rid of those size and screen position parameters used in the "secondary page" when the "parent page" opens?

Any help will be greatly appreciated!


Valery

AdamGundry
01-24-2003, 01:16 PM
Why not just use window.open() to open a new window for the parent page, and then use self.close() to remove the secondary window?

Something like this:
<a href="javascript:window.open('parent_page.html');self.close()">Close window</a>

Adam

Valery
01-24-2003, 01:26 PM
Adam,

thank you so much for your prompt reply!

You replied so quickly that I didn't even have time to test it, but will this

<a href="javascript:window.open('parent_page.html');self.close()">Close window</a>

help me get rid of the previous window size and position when a new one opens?

Thank you!

Charles
01-24-2003, 01:35 PM
Originally posted by AdamGundry
Why not just use window.open() to open a new window for the parent page, and then use self.close() to remove the secondary window?

Something like this:
<a href="javascript:window.open('parent_page.html');self.close()">Close window</a>

Adam Because

1 - that will give you a link that does nothing for one in ten users and

2 - that doesn't seem to solve the problem.

This might though:

<script type="text/javascript">
<!--
if (window.opener) {document.write('<a href="#">Close this Window</a>'); document.links[document.links.length-1].onclick = function () {self.close(); return false}} else {document.write('<a href="index.html">Home</a>')}
// -->
</script>
<noscript><a href="index.html">Home</a></noscript>

Valery
01-24-2003, 02:02 PM
Dear Charles,
dear Adam,


very unfortunately, neither of your suggestions work... i.e. the new window ("parent page") opens alright but still has the size and the position of the "secondary page" being closed...

Hmmmm....

Any ideas?

Thank you!


Valery

Charles
01-24-2003, 02:20 PM
I'm not understanding your problem. Can you post a URL?

Valery
01-24-2003, 02:41 PM
Yes, Charles, no problem, here is the URL:

http://vienna-doctor.com/ENG/Ovulation_day_EN_new.html

At the bottom of this page you will find both your and Adam's suggestions being implemented - do they work for you?

Thank you!

Charles
01-24-2003, 03:27 PM
I see the problem, you need to get rid of the piece of script:

function move_2_200_0()
{
self.moveTo(200,0)
self.resizeTo(600,700)
}

Instead, open the window thus:

<a href="http://vienna-doctor.com/ENG/Ovulation_day_EN.html" onclick="window.open(this.href, 'child', 'height=700,width=600,screenX=200,left=200,screenY=0,top=0,scrollbars'); return false">

Valery
01-24-2003, 04:18 PM
Thank you so much, Charles, for your tireless help!

I've done all you suggested, but cannot upload that page for a live testing because my server seems to have some hiccups at the moment...

As soon as I can check it out I will come back to you with the results.

Sorry for the delay and many thanks again!

Valery

Valery
01-24-2003, 04:46 PM
Charles,

I've uploaded it all now and checked it out as well...

Please be so kind as to check it out also:

1) The link to the the "Calculator" is here (second from top on the page) -

http://vienna-doctor.com/ENG/Links_ENG_new.html

it's just a copy of the original page but now it has your string -

<a href="http://vienna-doctor.com/ENG/Ovulation_day_EN_new.html" onclick="window.open(this.href, 'child', 'height=700,width=600,screenX=200,left=200,screenY=0,top=0,scrollbars'); return false">

2) The "Calculator" itself is still there (so that you can see how it works when you access this page as your entry page) -

http://vienna-doctor.com/ENG/Ovulation_day_EN_new.html

---------------------------

Now...

1) When I go directly to the "Calculator" (i.e., as my entry page), Adam's 'Close window' produces a resized Links_ENG_new.html ... too bad.

Yours instead works just great - thank you so much!

2) When I first go to http://vienna-doctor.com/ENG/Links_ENG_new.html and click on the "Calculator" link, the "Calculator" opens up very nicely - all properly resized and positioned - but I see a different 'Close... ' command line at the bottom (which works great all the same) than what was on the "Calculator" when I accessed it as my entry page.

Is this OK or have I misunderstood you and copied something wrong?

Please let me know.

Many thanks again!

Valery

Valery
01-24-2003, 04:57 PM
PS:

I think also need some kind of general solution (if there is one) to this problem...

I have many "secondary" pages on my site which open up in their specific sizes and take different positions on the viewer's screen.

If these pages are being viewed as "entry pages" (and many of them are - according to my "page views" statistics), how do I redirect people to the pages they SHOULD have come from AND lose the entry page's size and position all in one click (say, on "Close this window")???

Webskater
01-24-2003, 05:17 PM
You need a global variable. I don't know which platform you work on so I can only give you an example of how you handle this using ASP.
When someone visits your home page you set a session variable to true. Something like:
session("homepage") = true
On every other page, right at the top before any processing is done, you check the state of the variable. If it is false you redirect the user to your home page. The window opens full screen (if you want it to) and then you are in control of secondary windows.

Valery
01-24-2003, 05:20 PM
Oops!!!

Sorry, I have given the wrong URL in my previous posting...

The new page which contains a link to the calculator has this URL -

http://vienna-doctor.com/ENG/Links_ENG_new.htm

and NOT -

http://vienna-doctor.com/ENG/Links_ENG_new.html as previously posted!

Sorry...

Valery
01-24-2003, 05:32 PM
Originally posted by Webskater
You need a global variable. I don't know which platform you work on so I can only give you an example of how you handle this using ASP.
When someone visits your home page you set a session variable to true. Something like:
session("homepage") = true


This beats me completely... I am way too new to all this stuff to be able to control it through ASP (even if I knew what it is)...

Thank you anyway!

Valery