View Full Version : how to get hyperlink to open blank target if noscript

11-21-2012, 12:46 PM
I have a hyperlink that would normally open a photo album script using the onclick, but if JS is turned off I would like the link to open the image in a blank page and not in the same window, for the visitor to close it not knowing that it was in the same window, therefore losing the visitor.

What method could I do this in?

I tried to add it in like so, but it did not work, and only shows all the hyperlink code in the page instead.

<a <noscript>target="_blank" </noscript>href="images/<? echo($imageFile); ?>" class="highslide" onclick="return hs.expand(this)">

11-21-2012, 01:13 PM
Hi there needsomehelp,

there is no need to use the "noscript element". ;)

If javascript is disabled the link will work as normal.

Here is an example for you to test my assertion...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<html lang="en">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="language" content="english">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">

<title>javascript or no javascript</title>

<script type="text/javascript">

function init(){
document.getElementById('mylink').onclick=function() {
return false;
function expand(obj){
alert('this is javascript and the "this" is...\n\n' +obj);


<a id="mylink" href="http://www.coothead.co.uk/images/blood.jpg" target="blank">Do javascript or don't do javascript</a>



11-21-2012, 01:21 PM
To expand on this: Using progressive enhancement (http://en.wikipedia.org/wiki/Progressive_enhancement) you would have the default behavior of the link to open in a new window and remove that behavior with JavaScript.

11-21-2012, 01:52 PM