...

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



needsomehelp
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)">

coothead
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"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>

<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() {
expand(this);
return false;
}
}
function expand(obj){
alert('this is javascript and the "this" is...\n\n' +obj);
}
window.addEventListener?
window.addEventListener('load',init,false):
window.attachEvent('onload',init);
</script>

</head>
<body>

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

</body>
</html>


coothead

VIPStephan
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.

rodevin
11-21-2012, 01:52 PM
thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum