Ahmad
Ahmad

Reputation: 2129

how to display a link in a popup?

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

Answers (1)

mplungjan
mplungjan

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

Related Questions