How can I cause a link to open in a new small window?
I have images on a webpage that I want to have linked to another website, but in a new window of a certain size. In Dreamweaver, I used Window > Behaviors > onMouseClick, but for some reason, that isn't working. The image isn't recogni开发者_如何学JAVAzed as a link.
Is there any other way I can have it open a link in a new window of a set size, and actually have it work this time?
Here is the code produced by Dreamweaver:
<script language="JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>
The link:
<img src="images/portfolio/featured1.jpg" alt="Google" width="241" height="200" border="0" onclick="MM_openBrWindow('http://www.google.com','google','scrollbars=yes,width=650,height=500')" />
Well, this works for me in Opera. It's valid HTML, too.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Test popup</title>
</head>
<body>
<script type="text/javascript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>
<p>the link:
<img src="notice.png"
alt="Google"
width="241" height="200"
style="border: 0;"
onclick="MM_openBrWindow('http://www.google.com','google','scrollbars=yes,width=650,height=500')">
</body>
</html>
And this is better:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Test popup</title>
</head>
<body>
<script type="text/javascript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>
<p>the link:
<a href="http://www.google.com" onclick="MM_openBrWindow('http://www.google.com','google','scrollbars=yes,width=650,height=500'); return false;">
<img src="notice.png"
alt="Google"
width="241" height="200"
style="border: 0;"></a>
</body>
</html>
It's better because (a) there's a link, so you'll see the "hand" icon for the mouse; and (b) the link actually goes somewhere, so people with javascript turned off can still get to the content. (The "return false" on the "onclick" attribute means that people with javascript turned on only get the popup link. The "false" stops the browser following the normal link.)
精彩评论