+ Reply to Thread
Results 1 to 5 of 5

Thread: javascipt target blank

  1. #1
    gaptrast's Avatar
    gaptrast is offline x10 Sophmore gaptrast is an unknown quantity at this point
    Join Date
    Nov 2009
    Posts
    117

    javascipt target blank

    hi,

    I am using the onclick attribute instead of <a>.

    in <a> I can just set the target to _blank


    but how can i do that with <img>? this does not work: <img target="_blank" onclick"..." />

    HOW?
    LOOK RIGHT
    LOOK DOWN
    Questions you never knew you wanted answered - http://Wonderabout.info
    [New site!] Collection of fun computer pranks! - http://thefakevirus.com

  2. #2
    wplounge61 is offline x10Hosting Member wplounge61 is an unknown quantity at this point
    Join Date
    Sep 2010
    Posts
    1

    Re: javascipt target blank

    Here's how:
    <img src="image.jpg" onclick="window.open('http://x10hosting.com/')" />

  3. #3
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: javascipt target blank

    Using an onclick doesn't open a URL, so the concept of "target" doesn't really apply. What are you doing? Please post a minimal test case.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  4. #4
    gaptrast's Avatar
    gaptrast is offline x10 Sophmore gaptrast is an unknown quantity at this point
    Join Date
    Nov 2009
    Posts
    117

    Re: javascipt target blank

    hi, sorry misson...

    I used onclick="window.location('...')"

    Thanks wplounge61 your answer solved my question.
    LOOK RIGHT
    LOOK DOWN
    Questions you never knew you wanted answered - http://Wonderabout.info
    [New site!] Collection of fun computer pranks! - http://thefakevirus.com

  5. #5
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: javascipt target blank

    Why are you using JS with a non-anchor rather than the semantically correct anchor (<a>) elements? HTML should define the document structure. This is very important because computers, having no intelligence, need cues in order to deal with data. Elements are cues as to the meaning of the data contained within. If data is a link, it should be marked as such. You can still incorporate JS if necessary, but it shouldn't be relied on, and it fulfills a different purpose.

    More concretely: if you use JS rather than links, it will affect programs such as screen readers, browsers that don't support JS (such as on some cell phones) and search spiders, making it harder to index your site or reducing its page rank. There are also plenty of people who have JS disabled who won't be able to use your site.

    Basically, using a JS link and a non-anchor element is the Wrong Thing to do. Read "Accessible Pop-up Links" on A List Apart and "Links & JavaScript Living Together in Harmony" on Evolt for better ways (note that these are only a few articles of many; search the web for others).

    There is a suggestion for HTML5 to allow any element to function as a link, but it hasn't yet been submitted to the W3C.
    Last edited by misson; 11-09-2010 at 09:12 PM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to Thread

Similar Threads

  1. target url and uploading files
    By tanuj in forum Free Hosting
    Replies: 1
    Last Post: 05-19-2010, 06:10 AM
  2. Should we target GeoCities users?
    By zen-r in forum Off Topic
    Replies: 36
    Last Post: 06-30-2009, 03:07 PM
  3. PHP script - adding target="_blank" to links
    By booksgo in forum Programming Help
    Replies: 6
    Last Post: 12-17-2008, 05:04 PM
  4. Blank ads
    By AFIRE in forum Free Hosting
    Replies: 1
    Last Post: 04-08-2008, 06:47 PM
  5. Target Cuts PS2 Price By $30 Starting Feb 24
    By MicrotechXP in forum Gamer's Lounge
    Replies: 7
    Last Post: 02-21-2008, 11:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers