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?
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 DOWNQuestions you never knew you wanted answered - http://Wonderabout.info
[New site!] Collection of fun computer pranks! - http://thefakevirus.com
Here's how:
<img src="image.jpg" onclick="window.open('http://x10hosting.com/')" />
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.
hi, sorry misson...
I used onclick="window.location('...')"
Thanks wplounge61 your answer solved my question.![]()
LOOK RIGHT
LOOK DOWNQuestions you never knew you wanted answered - http://Wonderabout.info
[New site!] Collection of fun computer pranks! - http://thefakevirus.com
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.