Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A Simple question

Status
Not open for further replies.

milams

Programmer
May 28, 2004
32
US
I have a href link where I want to open a pop up window when someone clicks on the link. Ive tried it this way, but the parent page would change and say [NULL].

<div class="abs">
<a class="emaillink" href="javascript:window.open('email_subscript.htm','','width=300,height=300,top=50,left=40')">Join our Email List!</a>
</div>

So I went ahead and changed it to this below and it seems to work. My question is, is that the right way to write this?

<div class="abs">
<a class="emaillink" href="#" onclick="javascript:window.open('email_subscript.htm','','width=300,height=300,top=50,left=40')">Join our Email List!</a>
</div>
 
speaking for myself only, that is the preferred method. additionally, i'd add a [tt]return false;[/tt] to the onclick event and remove the [tt]javascript:[/tt] reference:

Code:
<a class="emaillink" href="#" onclick="window.open('email_subscript.htm','','width=300,height=300,top=50,left=40'); return false;">Join our Email List!</a>

the [tt]return false[/tt] ensures that the page won't scroll to the top (which the # specifies). another, even more stealth way is this:

Code:
<a class="emaillink" href="[red]email_subscript.htm[/red]" onclick="window.open('email_subscript.htm','','width=300,height=300,top=50,left=40'); return false;">Join our Email List!</a>

which will open the email_subscript.htm in a new page if the user has javascript enabled, but will still open the url in the SAME WINDOW if they have javascript disabled.

this, in my opinion, is the best way, aside from using the target attribute.



*cLFlaVA
----------------------------
[tt]( <P> <B>)13 * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
That works a lot better. Thanks cLFlaVA.
 
I like this one in my projects:

Code:
<a class="emaillink" href="email_subscript.htm" onclick="window.open('email_subscript.htm','','width=300,height=300,top=50,left=40'); return false;">Join our Email List!</a>

Except I change it slightly:

Code:
<a class="emaillink" href="email_subscript.htm" onclick="window.open(this.href,'','width=300,height=300,top=50,left=40'); return false;">Join our Email List!</a>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top