...

View Full Version : Target blank and close popup window



sonny
09-18-2011, 05:46 PM
I have a popup window that has a "link" inside it, which needs to have a target=_blank
but when ever clicked in IE, it stays inside the same window.

I tried all of the following, none work



<a href='http://www.myurl.net' onclick='window.close();' target='_blank'>

<a href="http://www.myurl.net" target="_blank" onClick="javascript:window.close()">

<a href="http://www.myurl.net" target="_blank" onClick="javascript: setTimeout(window.close, 10);">


Thanks
Sonny

Fou-Lu
09-18-2011, 06:25 PM
Despite the similar sounding names, Java is not the same as Javascript.
Moving from Java forum to Javascript forum.

hdewantara
09-19-2011, 12:50 PM
Shouldn't window.close() be used only on window opened with window.open() ?

sonny
09-19-2011, 08:23 PM
Shouldn't window.close() be used only on window opened with window.open() ?

I'm trying to close a popup window from within, and open a target blank
to help with clutter.

Sonny

blaze4218
09-19-2011, 08:27 PM
to close a popup window from within:

<a href="self.close ()">Close this Window</a>

blaze4218
09-19-2011, 08:29 PM
I think hdewantara was saying that window.whatever() will act on a window opened from the calling script - not the scripts own window.

//Edit
wait, I'm not right... I think that there are some methods that work on its own window, I was too quick to say that...

blaze4218
09-19-2011, 08:39 PM
what is your goal here? Are you closing one popup only to open another? which window is controlling all of this? could you re-use the same popup instead?

sonny
09-19-2011, 08:49 PM
what is your goal here? Are you closing one popup only to open another? which window is controlling all of this? could you re-use the same popup instead?

No I can't reuse the popup window, that would be easy but not practical for this.


I'm closing the popup window, and at the "same time" opening a "non popup" normal everyday target=_blank link when the user clicks on a link from within the popup window

Sonny

blaze4218
09-19-2011, 09:17 PM
I'm sorry if I don't quite grasp your terminology, but where is this "'non popup' normal everyday target=_blank link"?
By my estimates you have the original window (windowA) that opens a new window (windowB). windowB has the link <a href='http://www.myurl.net' onclick='window.close();' target='_blank'>Click me!</a> which triggers a chain reaction of
1) a new window (windowC) is opened with url 'http://www.myurl.net'
2) windowB closes itself
3) windowA remains the unchanged
If that is what you need, then all 3 worked when I ran them...

If, on the other-hand, your intentions were
1) windowB changes windowA's url to 'http://www.myurl.net'
2) windowB closes itself
then you might try this:

<a href='javascript:window.opener.location="http://www.myurl.net";window.close();'> Click me!</a>
and forget about that target blank thingy, because it won't allow windowB to close.

sonny
09-19-2011, 10:25 PM
I'm sorry if I don't quite grasp your terminology, but where is this "'non popup' normal everyday target=_blank link"?
By my estimates you have the original window (windowA) that opens a new window (windowB). windowB has the link <a href='http://www.myurl.net' onclick='window.close();' target='_blank'>Click me!</a> which triggers a chain reaction of
1) a new window (windowC) is opened with url 'http://www.myurl.net'
2) windowB closes itself
3) windowA remains the unchanged
If that is what you need, then all 3 worked when I ran them...

If, on the other-hand, your intentions were
1) windowB changes windowA's url to 'http://www.myurl.net'
2) windowB closes itself
then you might try this:

<a href='javascript:window.opener.location="http://www.myurl.net";window.close();'> Click me!</a>
and forget about that target blank thingy, because it won't allow windowB to close.
Know what, I just read a article about popups being bad for users in general and I agree,
I am going to bite the bullet and redesign without using any. if I do, it will only be for something really special like a print page or something.

What I was trying to do, was really quite simple to understand, I gave the three links I tried
this one below actually "WORKS" perfect in Firefox,

<a href="http://www.myurl.net" target="_blank" onClick="javascript: setTimeout(window.close, 10);">


BUT, IE for some reason always, opens the target blank window in the same dimensions as the popup.

This method you gave will not work if the user has javascript turned off, and bad for SEO I do not recommend anyone use this

<a href='javascript:window.opener.location="http://www.myurl.net";window.close();'> Click me!</a>

Thanks for weighing in, those links I posted should be useful to someone down the road
Sonny

Ok, let me explain just for the record, your reading something in a popup window, you then
click a link, you then go to a normal page, and the popup you were reading at gets closed.

blaze4218
09-19-2011, 10:41 PM
Ok, let me explain just for the record, your reading something in a popup window, you then
click a link, you then go to a normal page, and the popup you were reading at gets closed.

I'm tempted to say: that is what I tried to say with my second example.
But I won't quibble, I'm just glad you've read that article and come around to the light. I didn't want to say that and get all preachy, I just wanted to try and help you with your code.
On a side note, I don't recommend that code either. I didn't think about the SEO ramifications, but it was the only variation of 10-or-so that compensated for that IE bug you were talking about...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum