Solved

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

Posted on 2007-03-19
4
263 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
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…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now