SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2003
    Location
    USA
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to get a javascript link to open in a new window like target=_blank?

    I have this code,

    Code:
    <a href="#" onclick="window.location='http://YourSite.com';">click here</a>
    I want to make it so that it opens a new normal browser window just like target=_blank does.

    I tried using this tutorial, http://www.pageresource.com/jscript/jwinopen.htm but the code there just doesn't work.
    - Cyberkiller
    http://www.anythingchat.com <- Off-Topic Discussion Site
    http://www.onlinepharmacystore.net

  2. #2
    Always learning kigoobe's Avatar
    Join Date
    May 2004
    Location
    Paris
    Posts
    1,565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not very well in javascript, but ...

    try something like -

    Code:
    <a href="#" onClick="window.open('http://www.mysite.com','targetwindow'); return false;">Click here</a>

  3. #3
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    813
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    use '_blank' instead of 'targetwindow'. It will always open a new window instead of replacing content of newly opened window.

  4. #4
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •