Multi-function self close question

R

Raymond Wilk

I used javascript to open a new window, then used the following to close the
new window on the next click:
<body onBlur="self.close()" onClick="self.close()" bgcolor="#FFFFFF">

On the new window I want to place a link to another website, and I want the
new window to open the link in ANOTHER new window (not the parent window)
and then self close.

The idea is that on the first new window I have a picture, and a link to
another website that shows more information about the picture. If the person
just wants to see the picture and go back to my original page, the popup
window disappears. Or if they want more information they click on the link,
and another window pops up and the first popup window disappears. That way
they can look at the new page on someone else's website, and my website page
is still there for them to go back to.

Can I edit the <body> line I used to self close after opening a new window?
I don't want the link to open in the parent window...

Any suggestions?

Thanks,
Ray
 
M

Michael Winter

I used javascript to open a new window, then used the following toclose
the new window on the next click:
<body onBlur="self.close()" onClick="self.close()" bgcolor="#FFFFFF">

My first piece of advice is to not do that. There are many reasons why a
window might be sent to the background, and I don't think any of them mean
that the window should close. I frequently shift between page tabs on my
browser, and even external applications. That's what a multi-tasking
environment is supposed to allow. I do not expect to come back and find
that what I was looking gone.

[snip]
Can I edit the <body> line I used to self close after opening a new
window?
I don't want the link to open in the parent window...

That, frankly, doesn't make much sense. I assume you mean, "How do I
modify the <body> line to open a new window, then close the current
window?" If so, call openThenClose(), below:

function openThenClose() {
window.open('theURL','windowName');
window.close();
}

If that isn't what you want, please rephrase your question.

Mike
 
R

Raymond Wilk

That, frankly, doesn't make much sense. I assume you mean, "How do I
modify the <body> line to open a new window, then close the current
window?" If so, call openThenClose(), below:

function openThenClose() {
window.open('theURL','windowName');
window.close();
}

If that isn't what you want, please rephrase your question.

Mike

I got that to work, but I'm missing one function I didn't make clear. If the
link in the window is NOT clicked I would like the window to close.

After following your advice, I have a window that contains a picture and a
link to another site. If the link is clicked, the first window closes and a
new window opens showing the other site. Perfect. But if the person viewing
the first window just wants to look at my picture and NOT follow the link, I
would like that window to self close on the next click.

If I use <body onBlur="self.close()" onClick="self.close()"> or just <body
onBlur="self.close()"> it over-rides what you gave me, and closes the window
when the link is clicked.

Thanks for helping me, Mike. I'm a graphics guy and all I know how to do
with scripts is copy-paste!
Ray
 
M

Michael Winter

[snip]
After following your advice, I have a window that contains apicture and
a link to another site. If the link is clicked, thefirst window closes
and a new window opens showing the other site.Perfect. But if the person
viewing the first window just wants tolook at my picture and NOT follow
the link, I would like thatwindow to self close on the next click.

So,

1) User clicks on link in main website. This opens new window with
image a link.
2a) User clicks link in new window. Second window opens containing web
page at URL. First window closes.
2b) User clicks elsewhere in page. First window closes, leaving
original site.

That correct? If so, try:

In first window:

<head>
<title>...</title>

<style type="text/css">
body {
bottom: 0;
position: absolute;
top: 0;
}
</style>
</head>

<!-- I still recommend not using onblur="self.close()" -->
<body onclick="self.close()">
<!-- image -->
</body>

That does what I've listed above. The style sheet is a kludge to ensure
that Opera (and possibly other browsers) register the body click anywhere
on the page. Without it, the body only extends as far as the last element.

If this *still* isn't correct, I apologise for being so dense. :)

[snip]

Mike
 

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

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top