Reputation: 2129
I have a link with the following code.
<a href="www.facebook.com">Facebook</a>
I want when I click on the facebook link, it should open the window in a popup. Now it is opening in the same window.
How will I do this?
Upvotes: 1
Views: 680
Reputation: 178285
XHTML Strict:
window.onload=function() {
document.getElementById('fbLink').onclick=function() {
var w=window.open(this.href,this.getAttribute("rel"),"width=500,height=600");
return w?false:true
}
}
using
<a href="http://www.facebook.com" rel="external" title="Open Facebook" id="fbLink">facebook</a>
Safest:
<a href="http://www.facebook.com" target="_blank">Facebook</a>
Possible (here inline):
<a href="http://www.facebook.com" target="_blank"
onclick="var w=window.open(this.href,this.target,'width=500,height=600');
return w?false:true">Facebook</a>
Onobtrusive:
window.onload=function() {
document.getElementById('fbLink').onclick=function() {
var w=window.open(this.href,this.target,'width=500,height=600');
return w?false:true
}
}
using
<a href="http://www.facebook.com" target="_blank" id="fbLink">facebook</a>
Upvotes: 2