...

View Full Version : onClick open in original window: HELP!!



VatsaL
11-12-2006, 01:34 AM
I press a button.

A popup opens, showing me a list of links.

I click on a link.

The popup closes, and the new link opens in a new window at the same time.

what should I put instead of onClick=window.open('http://www.microsoft.com/','') or make any changes anywhere else, so that the link I click on opens in the original window where I pressed the button to open the popup?

Also, how should I convert the checkbox links to the normal <a href> ones??

here s the code:

<html>
<head>
<script language="JavaScript" type="text/javascript">
<!-- Copyright 2001, Sandeep Gangadharan -->
<!-- For more free scripts go to http://sivamdesign.com/scripts/ -->
<!--
var X = 200; // change the # at the left for a fixed X co-ordinate to accommodate browsers other than IE or NS
var Y = 200; // change the # at the left for a fixed Y co-ordinate to accommodate browsers other than IE or NS

if (navigator.appName.indexOf("Netscape")!=-1) {
document.captureEvents(Event.MOUSEMOVE)
function getcoords(e) {
X = parseInt(e.screenX) - 80; // change the # at the left to further adjust the left-margin depending on the size of the window
Y = parseInt(e.screenY) - 60; // change the # at the left to further adjust the top-margin depending on the size of the window
return true;}
document.onmousemove = getcoords;

function openWin() {

if (navigator.appName.indexOf("Microsoft")!=-1) {
X = parseInt(event.screenX) - 80; // change the # at the left to further adjust the left-margin depending on the size of the window
Y = parseInt(event.screenY) - 60; } // change the # at the left to further adjust the top-margin depending on the size of the window

display=window.open('','NewWin','menubar=0,location=no,status=no,directories=no,toolbar=no,scrollbar s=yes,height=110,width=190')
message="<font face='verdana, arial, helvetica, san-serif' size='2'><form>";
message+="<input type='checkbox' onClick=window.open('http://www.microsoft.com/','') onBlur='window.close();' />Microsoft Corp.<br />";
message+="<input type='checkbox' onClick=window.open('http://home.netscape.com/','') onBlur='window.close();' />Netscape Corp.<br />";
message+="<input type='checkbox' onClick=window.open('http://www.macromedia.com','') onBlur='window.close();' />Macromedia Inc.<br />";
message+="<input type='checkbox' onClick=window.open('http://www.symantec.com','') onBlur='window.close();' />Symantec Corp.<br />";
message+="</form></font>";
display.moveTo(X,Y);
display.document.write(message); }
}
// -->
</script>
</head>
<body>
<font face="verdana, arial, helvetica, san-serif" size="2">
<form><input type="button" value="Some Links" onClick="openWin()" /></form>
</font>
</body>
</html>

thanks,

VatsaL

mark87
11-12-2006, 02:03 AM
onClick=window.opener.document.location.href='http://www.microsoft.com/'

To change them to normal links you'll need to replace the relevant parts with anchors eg.

message+="<a href='http://www.microsoft.com/' onBlur='window.close();'>Microsoft Corp.</a>";

That Javascript looks fairly old though as the font tag isn't used anymore...

VatsaL
11-12-2006, 02:10 AM
onClick="parent.location.href='http://www.microsoft.com/'" :)

Dosent work!!
here is the page with the CHANGED onClick command (onClick="parent.location.href)

http://www.b3ta.cr3ation.co.uk/data/htm/links.htm

mark87
11-12-2006, 02:11 AM
Look at my updated post above. ^

david_kw
11-12-2006, 02:13 AM
It still looks like document.location.href not parent in the example link you have.

david_kw

VatsaL
11-12-2006, 02:15 AM
It still looks like document.location.href not parent in the example link you have.

david_kw

the example link was AFTER I modified the code according to the first suggestion.

The first original code without any modifications is posted in the first ever post.

mark87
11-12-2006, 02:18 AM
Try my edited post above. ^

Also to make the anchors link to the original window you'd have to do something like:

message+="<a href='#' onclick=window.opener.document.location.href='http://www.microsoft.com/' onblur='window.close();'>Microsoft Corp.</a>";

VatsaL
11-12-2006, 02:19 AM
onClick=window.opener.document.location.href='http://www.microsoft.com/'

To change them to normal links you'll need to replace the relevant parts with anchors eg.

message+="<a href='http://www.microsoft.com/' onBlur='window.close();'>Microsoft Corp.</a>";

That Javascript looks fairly old though as the font tag isn't used anymore...

Hey javascript does work, but microsoft.com would open up in the same popup window, and NOT in the parent window, where the button was located.

It seems obvious that it would, because when the links opened in a new window, the popup window got a chance to get "blurred" and then close according to the function is was given.

But I need to combine the onClick function, so that when the user clicks, the popup first closes, and then the parent window would open up with the link.
Is that possible??
oh, n the script is a bit old!!

thanks,

VatsaL

mark87
11-12-2006, 02:21 AM
Hehe we're getting a bit confused posting while eachother is posting!

Try the updated code (again)...

message+="<a href='#' onclick=window.opener.document.location.href='http://www.microsoft.com/' onblur='window.close();'>Microsoft Corp.</a>";

VatsaL
11-12-2006, 02:22 AM
Try my edited post above. ^

Also to make the anchors link to the original window you'd have to do something like:

message+="<a href='#' onclick=window.opener.document.location.href='http://www.microsoft.com/' onblur='window.close();'>Microsoft Corp.</a>";

yeah, its confusin!

okay, the code works, the link opens in the parent window, but the popup window dosent close, as it does not get a chance to be blurred!
can it be combined to the onclick function or something like that, so that the opening of the new link AND the closing of popup happens at the same time??

with your code, the link DOES open in the parent window, but the popup wont close as it remains in focus while the link opens in the parent window!!

mark87
11-12-2006, 02:23 AM
It should do it automatically... can you update the online page again to the latest code you have so far?

VatsaL
11-12-2006, 02:26 AM
It should do it automatically... can you update the online page again to the latest code you have so far?

here it is, the first link.

http://www.b3ta.cr3ation.co.uk/data/htm/787links.htm

mark87
11-12-2006, 02:29 AM
Ah I see, what's happening is it's not changing the focus from the popup so onblur is not running until you click back to the main window.

Try setting the focus back to the main window.

message+="<a href='#' onclick=window.opener.document.location.href='http://www.microsoft.com/';window.opener.focus() onblur='window.close();'>Microsoft Corp.</a>";

You could also just skip the onblur and close the window when a link is clicked (probably simpler).

message+="<a href='#' onclick=window.opener.document.location.href='http://www.microsoft.com/';window.close()>Microsoft Corp.</a>";

VatsaL
11-12-2006, 02:32 AM
Ah I see, what's happening is it's not changing the focus from the popup so onblur is not running until you click back to the main window.

Try setting the focus back to the main window.

message+="<a href='#' onclick=window.opener.document.location.href='http://www.microsoft.com/';window.opener.focus() onblur='window.close();'>Microsoft Corp.</a>";

YAYAYAYAYAY IT WORKS BEAUTIFULLY!!
THANKS A BILLION
that was the only thing left to complete my site.
actually I am making a hybrid type search engine, which I hope will suit the needs for every homepage. Still have to add some tools, for which I needed the code, thanks.


VatsaL

mark87
11-12-2006, 02:34 AM
No problem, glad I could I help :) ; stick around!

It looks good to me but if you want a proper review, ask for one in the reviews section. ;)

VatsaL
11-12-2006, 02:36 AM
No problem, glad I could I help :) ; stick around!

It looks good to me but if you want a proper review, ask for one in the reviews section. ;)

I will, after I get it all properly done, this is completely unfinished, have loads to add.

thanks anyways, cya l8rs


VatsaL



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum