0

I have an html page.In that i used 3 images with a tag i am navigating page. Is it possible to know which image clicked in newly opened html page.

Pavan573
  • 81
  • 1
  • 1
  • 5

2 Answers2

0

Sure, have the link the image uses have a query string or hash tag, like so:

<a href="YourSite.com/YourPage.htm?Image=1"><img src="image.png"></a>

And then pull that like so:

function getQuerystring(key, default_)
{
  if (default_==null) default_="";
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
}
if (getQuerystring("Image")=="1"){ ... }

Query string code from javascript query string and from Blogging Developer originally

Community
  • 1
  • 1
Chris Carew
  • 1,398
  • 10
  • 6
-1

yes using javascript.

you can with JS + Ajax then you can insert an entry in Database on image onclick event.

Give us more detail/code if you want to know more about this solution.

Kashyap
  • 479
  • 5
  • 17
  • -1, I'd never recommend anyone doing this. Slow and not certain you always get the right referral image. Sorry... – Asken Apr 07 '12 at 06:00