Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7762411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:23:44+00:00 2026-06-01T14:23:44+00:00

I have to use javascript to make links instead of for several unimportant reasons,

  • 0

I have to use javascript to make links instead of for several unimportant reasons, and I want for it to behave like even though im not using it. Not the affects thats easy, but I want to be able to hold down shift while clicking to open a new window and to open it in a new tab if they are holding down ctrl. How would I do this? Also, it has to be compatible with IE9.

[edit] Also, this is going to be in an iframe

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:23:45+00:00Added an answer on June 1, 2026 at 2:23 pm

    I guess you want something like this:

    JSFiddle

    http://jsfiddle.net/MXuVY/3/

    JavaScript

    var ctrlPressed = false;
    $('#link').click(function () {
        var link = 'http://stackoverflow.com/';
        if (ctrlPressed) {
            window.open(link,'_blank');
        } else {
            window.location = link;
        }
        return false;
    });
    $(document).keydown(function (e) {
        if (e.keyCode === 17) {
            ctrlPressed = true;
        }
    });
    $(document).keyup(function (e) {
        if (e.keyCode === 17) {
            ctrlPressed = false;
        }
    });
    

    ​

    HTML

    <span id="link">Link to stackoverflow</span>​
    

    ​Version without jQuery

    JSFiddle

    http://jsfiddle.net/MXuVY/6/

    JavaScript

    function addEvent(el, eType, fn, uC) {
        if (el.addEventListener) {
            el.addEventListener(eType, fn, uC);
            return true;
        } else if (el.attachEvent) {
            return el.attachEvent('on' + eType, fn);
        } else {
            el['on' + eType] = fn;
        }
    }
    
    var ctrlPressed = false,
        a = document.getElementById('link'),
        link = 'http://stackoverflow.com/';
    
    addEvent(a, 'click', function () {
        if (ctrlPressed) {
            window.open(link,'_blank');
        } else {
            window.location = link;
        }
        return false;
    });
    addEvent(document, 'keydown', function (e) {
        if (e.keyCode === 17) {
            ctrlPressed = true;
        }
    });
    addEvent(document, 'keyup', function (e) {
        if (e.keyCode === 17) {
            ctrlPressed = false;
        }
    });
    

    ​

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an HTML file and I want to use javascript to call a
Assume you have a page in ASP.NET where it makes sense to use JavaScript/jQuery
I have the following in my HTML5 code which makes use of javascript: var
I use an externel javascript file and i have this, function getdropdownvalue() { alert($(#<%=DLState.ClientID%>));
I need to use Substring in Javascript. But despite my searches, i have an
What is the best way to pause in JavaScript. I have attempted to use
We have a javascript function we use to track page stats internally. However, the
I have a javascript which I didn't write but I need to use it
I have a Javascript Map kit, and it use Image object to load images.
I only have very basic knowledge on Javascript and I want to be able

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.