Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2007-03-19
4
Medium Priority
?
273 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 1000 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 1000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…

670 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