A Href Link Popup

This is a JavaScript tutorial it is a very simple one, nothing really advanced, but a tutorial I think that I should write about. Usually when I search for a popup window using a href link I usually find examples where you have to add a code in the head tag then add the call to your intended link in the body tag, shown below.

Within the head tag Add this

<SCRIPT TYPE=”text/javascript”>
<!–
function popup(Newlink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(Newlink) == ’string’)
href=Newlink;
else
href=Newlink.href;
window.open(href, windowname, ‘width=300,height=300,scrollbars=yes’);
return false;
}
//–>
</SCRIPT>

Within the body tag add this

<A HREF=”your url” onClick=”return popup(this, ‘notes’)”>popup</A>

To me this is too much code to add to the head tag especially if you already use tons of JavaScript on your site along with multiple CSS files. So on my sites I tend to use the following code on a regular basis, shown below.

Within the body tag add this, that’s all

<a href=”javascript:void(0)” onclick=”window.open(’your url’,'windowname’,'width=300,height=300,top=25,scrollbars=yes’)”></a>

Working Example: Click Here

Comments are closed.