Forum Moderators: open
I have pieced together this code (I am learning JS as I go) for nice rollover table cells but need the onclick action to open the link in a new window
I have highlighted the incriminating text in bold below
Anybody know what I am missing here?
Thanks
Limbo
-----------------------------------------
<html>
<title> Why wont the page load in new window?</title>
<head>
<SCRIPT language=Javascript>
<!--
function mOvr(src,clrOver){
if (!src.contains(event.fromElement)){
src.style.cursor = 'hand'; src.bgColor = clrOver;
}
}
function mOut(src,clrIn){
if (!src.contains(event.toElement)){
src.style.cursor = 'default';
src.bgColor = clrIn;
}
}
function mClk(src){
if(event.srcElement.tagName=='TD'){
src.children.tags('A')[0].click();
}
}
//-->
</SCRIPT>
</head>
<body bgcolour="#ffffff">
<table width="100" height="20">
<tbody>
<tr>
<td onMouseOver="mOvr(this,'#999999');"
onClick="self.location='http://www.google.com', target='_blank'"
onMouseOut="mOut(this,'#EBEBEB');" valign=top bgcolor=#EBEBEB colspan=5><font color="#FF6666"></font></td>
</tr>
</tbody>
</table>
</body>
</html>
You could also put this script in a real HTML anchor to serve 2 purposes :
a) make it work for JS disabled browsers (about 8 % of market)
b) make this link readable by search engine spiders, so pop-up page is indexable
I use this in original page :
<a href="page.htm" onClick="window.open('page.htm','','scrollbars=XX,resizable=XX,
menubar=XX,toolbar=XX');return false;"
target="_blank">Anchor text</a>
And this in pop-up <body> tag:
onLoad=window.resizeTo(WWW,HHH);
Just to add to Macguru's post:
<a href="page.htm" onClick="javascript:window.open('page.htm','_blank','scrollbars=XX,resizable=XX,
menubar=XX,toolbar=XX,width=XX,height=YY');return false;"
target="_blank">Anchor text</a>
then you don't need the onLoad=window.resizeTo(WWW,HHH); in your pop-up.
Also, you don't need the javascript to do the mouse-over, you can do it in css:
A {
color: #FF6666;
background-color: #EBEBEB;
cursor: default;
}
A:hover {
background-color: #999999;
cursor: hand;
}
Then you won't need your <font color="#FF6666"></font> tag either.
Shawn
Correct me if I'm wrong but the code you have posted only works on text links?
I wanted a new window to open when the 'onclick' function was called anywhere over a table cell regardless of it's text content. This way I can save time making rollover images for a navigation menu and reduce download times of the page by having the rollover as JS.
Is it possible to do this so the link for the table cell will be spidered by SE's.
Cheers Shawn
I see that now :)
With the CSS, will it change the background of the entire table cell? or will it just change the background of the link text?
Just the text in the <A> tag. And I don't think you can define :hover css properties for other tags, just for <A>. There are 2 things that you can do, however:
1. Define height and width css properties of the <A> tag to be 100% (i.e. 100% of what contains it, being the table cell). Not sure if it will work, or how browser dependant it is. You can try it.
2. And this one I am sure of... Between the <A> and the </A> define a "<div> your link text </div>". Then in the css you can define the size of the div to be whatever you want.
Shawn