Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-21-2012, 12:46 PM   PM User | #1
needsomehelp
Regular Coder

 
Join Date: Oct 2009
Posts: 302
Thanks: 4
Thanked 3 Times in 3 Posts
needsomehelp can only hope to improve
how to get hyperlink to open blank target if noscript

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.

Code:
<a <noscript>target="_blank" </noscript>href="images/<? echo($imageFile); ?>" class="highslide" onclick="return hs.expand(this)">
needsomehelp is offline   Reply With Quote
Old 11-21-2012, 01:13 PM   PM User | #2
coothead
Senior Coder

 
coothead's Avatar
 
Join Date: Jan 2004
Location: chertsey, a small town 25 miles south west of london, england.
Posts: 1,549
Thanks: 0
Thanked 195 Times in 191 Posts
coothead will become famous soon enough
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...
Code:
<!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
coothead is offline   Reply With Quote
Old 11-21-2012, 01:21 PM   PM User | #3
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,599
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
To expand on this: Using progressive enhancement you would have the default behavior of the link to open in a new window and remove that behavior with JavaScript.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 11-21-2012, 01:52 PM   PM User | #4
rodevin
New to the CF scene

 
Join Date: Nov 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
rodevin is an unknown quantity at this point
thanks
rodevin is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:05 PM.


Advertisement
Log in to turn off these ads.