Forum Moderators: open

Message Too Old, No Replies

onClick show div + open URL in new tab?

need some help

         

drfresh

3:08 am on Feb 16, 2011 (gmt 0)

10+ Year Member



Alright, basically this is what I'm trying to do.

I want to display a div when a link is clicked, but at the same time I want to open a url in a new tab.

I found some code and changed it very slightly, here's my attempt:

Preview:
[obama2011.net ]
Code:
<a onclick="document.getElementById('div_name2').style.display='';return false;" 
href="http://google.com" target="_blank" style="text-decoration:none;border-bottom:1px dotted blue;">
Sign up</a>
<br />
<div id="div_name2" style="display:none;margin:15px 15px 0px 15px;padding:5px;border:1px solid #aaa;">
Aweber optin form here.

</div>


If you notice in the preview when you highlight the link it says it'll go to google if you click, but it never does and just displays the div.

I really don't know much at all about this stuff, I just fumble around with other people's code and usually figure it out, but I don't think I can get this one on my own. :P

Any help is much appreciated..

drfresh

3:49 am on Feb 16, 2011 (gmt 0)

10+ Year Member



HOLY CRAP

i figured it out myself lol...

<A href="javascript:void(0)"
onclick="window.open('http://google.com'); document.getElementById('div_name2').style.display='';return false;">
Sign up</A>

<div id="div_name2" style="display:none;margin:15px 15px 0px 15px;padding:5px;border:1px solid #aaa;">
Aweber optin form here.

</div>


thanks anyhow.

Fotiman

1:47 pm on Feb 16, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Welcome to WebmasterWorld!
A slightly better approach might be something like this:

<a href="http://example.com" onclick="window.open(this.href); document.getElementById('div_name2').style.display='';return false;">Sign Up</a>

This way, hovering over the link should show the destination in the browser status bar, and also for people with JavaScript disabled, the link will still (at the very least) take them somewhere.