Solved

Referrer blank when using onClick

Posted on 2004-09-14
11
907 Views
Last Modified: 2012-06-21
I just added functionality to my page that acts as a link using onClick(window.location.href = url) for a table row.

I also have an image with a link that points to the same url.

When the image is clicked, I get referrer information.

When the onClick option for the table row is used, referrer information is blank.

Is there an easy fix to this problem??
0
Comment
Question by:MrChuck
[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
  • 3
  • 3
  • +1
11 Comments
 
LVL 33

Expert Comment

by:knightEknight
ID: 12055898
you can try this:

if you name your link:

  <A href="someurl.htm" name="myLink"><IMG src="myimage.jpg" border="0" /></A>

then you can do this:

  onClick='document.anchors["myLink"].click();'
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 12055940
this is better:

<HTML>
<BODY>
<A href="#" name="myLink" id="myLink" onclick="alert(0);return false;">myLink</a><br />
<A href="#" name="test"   onclick='document.getElementById("myLink").click();return false;'>test</a></br>
</BODY>
</HTML>
0
 
LVL 33

Accepted Solution

by:
knightEknight earned 125 total points
ID: 12055962
in other words, give your link a name and an identical id:
   <A href="someurl.htm" name="myLink" id="myLink" ><IMG src="myimage.jpg" border="0" /></A>

then in your onclick do this:
   onclick='document.getElementById("myLink").click();'
0
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!

 
LVL 14

Expert Comment

by:dfu23
ID: 12056006
I think that the refferer information is only passed with an anchor tag ... not sure how to get around this for your table row onclick ... can you put an anchor in the row ... is that a possibility?
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 12056027
I tried to get around that by executing the click() of the anchor in the onclick of the table row.
0
 

Author Comment

by:MrChuck
ID: 12056253
The click idea worked when I hard coded the url. However, since I have a bunch of different url's, I am trying to pass it to the function.

What I have below doesn't work.

function SeePic(url) {
document.getElementById(url).click();
}

0
 
LVL 19

Expert Comment

by:dakyd
ID: 12056319
Maybe try this?  Replace "myLink" with the id of the <a> tag.  Hope that helps.

function SeePic(url) {
var theLink = document.getElementById("myLink");
theLink.href = url;
theLink.click();
}
0
 

Author Comment

by:MrChuck
ID: 12056413
The id is what is getting passed to the function.

Eg.  SeePic("MyLink")
0
 
LVL 19

Expert Comment

by:dakyd
ID: 12056533
Hm, you're passing in the id of the link?  That'll let you get the correct element, but won't let you change what it points to.  So for example, given this:

<script type="text/javascript">
function SeePic(url) {
document.getElementById(url).click();
}
</script>

<a href="http://www.google.com" id="myLink">Go To Google</a>

then SeePic("myLink") will always take you to Google.  I understood your question to mean that you want to change the location where the link points, so you can go to different sites/locations.  If you want to do that, then you'll need something more like this:

<script type="text/javascript">
function SeePic(url, newLocation) {
var theLink = document.getElementById(url);
theLink.href = newLocation;
theLink.click();
}
</script>

So now, a call to SeePic("myLink", "http://www.yahoo.com") will take you to yahoo.  Hopefully that helps, but if I misunderstood or that's not clear, then ask away.
0
 

Author Comment

by:MrChuck
ID: 12056753
Actually it my ignorance in JavaScript that is the problem.. lol

I was expecting the url that is passed to the function to show up in the browser source. (Like Im used to seeing with PHP)

However since Javascript is client side, it won't show up but it will execute properly.

0
 
LVL 19

Expert Comment

by:dakyd
ID: 12056790
Oh, heh ... glad you got what you wanted.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Add - in a loop to first and last element. 6 41
Problem in javascript 17 26
Boolean 13 24
Javascript: Range object 16 14
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

733 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