Solved

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

Posted on 2007-03-19
4
267 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
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

821 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