Solved

Ctrl+click javascript, hightlights text... TNAME...

Posted on 2007-03-19
4
269 Views
Last Modified: 2008-02-01
hi all, i asked this question and had it solved, but i didn't realize 1 thing. Here's the question i asked before

http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_22436823.html#a18688209

here's the problem. When i ctrl+Click, it briefly highlights the text that i'm clicking on (Selecting it) and then it disappears. I want to stop this behavior. How do i do that? thanx all
0
Comment
Question by:gyra
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 15

Accepted Solution

by:
stanscott2 earned 250 total points
ID: 18754025
My advice is to NOT use an anchor <a> tag at all.  It's not really a hyperlink, after all.

Instead, use any other HTML element, such as <span>:

<span style="cursor:pointer" onclick="xxxx()">Display text</span>

0
 
LVL 30

Assisted Solution

by:third
third earned 250 total points
ID: 18754227
try,

<html>
<head>

<style>

a#fakeLink  {text-decoration:underline; color:blue; cursor:pointer;}
a#fakeLink:active   {color:ee66dd;}

</style>

<script>

function ctrlYes() {  
  alert('Ctrl!');
  return false;
}

function ctrlNo() {  
  alert('No Ctrl!');
  return false;
}

function testCtrl(obj, event) {
    if (document.selection)
       document.selection.empty();
    if (!event) event = window.event;
    if (event.ctrlKey) {      
      obj.style.backgroundColor = obj.style.backgroundColor=='#00008b'?'':'#00008b';
       //ctrlYes();
     }
     else  {
        //ctrlNo();
     }
return false;
}
</script>
</head>
<body>

<a id="fakeLink" onClick="testCtrl(this, event);return false;">Click this link</a>

</body>
</html>
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question