0

I have the following HTML that pops up a window when I click the 'Open Sesame' link:

<a href="/about-us/" title="Find out About Us" onclick="javascript:void window.open('/about-us/','1329304840803','width=1050,height=500,toolbar=0,menubar=0,location=0,status=1,scrollbars=1,resizable=1,left=0,top=0');return false;">Open Sesame</a></li>

However, I was wondering is it possible I could remove the 'onClick' part and just have the javascript within the href & still get the same new window effect. Is this possible?

Many thanks for any pointers

4
  • 3
    I bet trying it would have been faster... Commented Jun 27, 2012 at 15:47
  • Good call, Dimitri. Much faster. I just assumed I needed the onClick. Commented Jun 27, 2012 at 15:49
  • 1
    Rule of thumb i use: Never assume anything :) Commented Jun 27, 2012 at 15:50
  • 2
    Hehe, I assumed you would say that. Commented Jun 27, 2012 at 15:50

1 Answer 1

3

Yes you can:

<a href="javascript:void window.open('/about-us/','1329304840803','width=1050,height=500,toolbar=0,menubar=0,location=0,status=1,scrollbars=1,resizable=1,left=0,top=0');" title="Find out About Us">Open Sesame</a>

http://jsfiddle.net/Curt/NqfMX/


However, I would recommend an event listener for this. It makes your HTML code much tidier and seperates the function from the HTML design:

<a class="opensesame" href="/about-us/" title="Find out About Us">Open Sesame</a>​​​​​​​​​​​​​​​​​​​​​​

​$(function(){
    $("a.opensesame").click(function(e){
        e.preventDefault();
        window.open('/about-us/','1329304840803','width=1050,height=500,toolbar=0,menubar=0,location=0,status=1,scrollbars=1,resizable=1,left=0,top=0');
    });
});​

http://jsfiddle.net/Curt/NqfMX/1/

Sign up to request clarification or add additional context in comments.

7 Comments

Many thanks, Curt. I'm off now with my offline tail between my legs.
Hey Curt. Unfortunately this doesn't seem to work with IE. I'm using IE9. Any ideas why not?
@mcgarriers Hi, I'm running IE 9.0.8112 and both of my fiddles work fine on that.
Thanks, Curt. I will try again in a minute & see how I get on :) Back in a minute...
JsFiddle appears to be having a "moment"... :)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.