WeBWorK Problems

How add _blank as html link attribute?

How add _blank as html link attribute?

by Murray Eisenberg -
Number of replies: 3
Is it possible to add the equivalent of the standard html attribute target="_blank" for an html link reference within a question -- so that the target page will open in a new window rather than replace the current window containing the question? How?

(If not, this is annoying, as it means that a call to a utility, e.g., a plotter, does not readily allow students to use the utility at the same time as they are working on the problem.)
In reply to Murray Eisenberg

Re: How add _blank as html link attribute?

by Jason Aubrey -
Murray,

You can do this with javascript. An example is given here:

http://webwork.maa.org/wiki/HtmlLinks

Jason
In reply to Jason Aubrey

Re: How add _blank as html link attribute?

by Murray Eisenberg -
Thanks.

Does your answer mean there's no direct way to exploit the standard html target attribute? I find that surprising!

Also, in the example to which you refer, the URL is hardcoded into the javascript. That's a bit unpleasant, as it means that one would need multiple version of essentially the same javascript function definition in case one wanted links to two different URL's on the same page.
In reply to Murray Eisenberg

Re: How add _blank as html link attribute?

by Michael Gage -
It is not documented, unfortunately, but you can do what you want. The macro allows an extra variable:
htmlLink($url, $text, $option)

which becomes
<a href="$url" $option >$text</a>

You can put any string you want in $option including
target="_blank".

Since there is no error checking you can get complete HTML garbage if you put the wrong thing in the last slot, which is probably why it wasn't documented. It deserves to be rewritten with more safe features. :-)

-- Mike