-3

i need a way to open a specific link (for example www.google.it) on ANY mouse left click on the page

So for example, if there is a button called "home" and the user click on it, it will open two pages home.htm and www.google.it

Is there a way?

I'm trying to use a simple javascript code but it's not working with supersized :)

http://inogroup.it/new/313/slideshow/fade.html

ScrollerS
  • 11
  • 4

2 Answers2

0

Just use window.open. You can read more here: http://www.w3schools.com/jsref/met_win_open.asp

For example, the code using jQuery would be like this (assuming the link has an id "home"):

$("#home").on("click", function() {
    window.open("http://www.google.it");
});

And another example not using jQuery but just plain old JavaScript:

document.getElementById("home").onclick = function() { window.open("http://www.google.it"); }

Your link will open on the current tab, and the other url (google.it) will open on a new tab.

Alvaro Montoro
  • 28,081
  • 7
  • 57
  • 86
  • is that code javascript? :) and, how to add an id for my image with supersized code? http://inogroup.it/new/313/slideshow/fade.html Thank you very much! – ScrollerS Oct 10 '14 at 16:47
  • That code is JavaScript. I don't know what "supersized code" is (and sorry, I won't follow the link you shared). But if you want to do it for an image, it would be something like this: `` – Alvaro Montoro Oct 10 '14 at 16:51
  • i added this but it seems not working? maybe i should add id somewhere... is it not possible to remove the id and make it general for ALL the page? :) – ScrollerS Oct 10 '14 at 16:52
  • the problem is that i've something like this {image : 'http://inogroup.it/new/313/1.gif', title : 'Quiet Chaos by Kitty Gallannaugh', url : 'http://www.nonsensesociety.com/2010/12/kitty-gallannaugh/'}, – ScrollerS Oct 10 '14 at 16:53
  • That is some incorrect json code that I don't really know what has to do with the question. – Alvaro Montoro Oct 10 '14 at 18:50
  • @AlvaroMontoro, this isnt a pure javascript solution.. this is jquery. – Akin Okegbile Oct 10 '14 at 19:44
  • Ok, I just edited the solution to add a pure JavaScript alternative. – Alvaro Montoro Oct 10 '14 at 19:50
0

Building on Alvaro's answer a pure java script solution

document.addEventListener('click', function(event) {
    if (/* your disabled check here */) {
      // Kill the event
      event.preventDefault();
      event.stopPropagation();
    }

    // Doing nothing in this method lets the event proceed as normal
  },
  true  // Enable event capturing!
);

This answer is built on this previously answered question. JavaScript - Hook in some check on all 'click' events

Community
  • 1
  • 1
Akin Okegbile
  • 1,108
  • 19
  • 36