MrChuck
asked on
Referrer blank when using onClick
I just added functionality to my page that acts as a link using onClick(window.location.hr ef = 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??
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??
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.getEleme ntById("my Link").cli ck();retur n false;'>test</a></br>
</BODY>
</HTML>
<HTML>
<BODY>
<A href="#" name="myLink" id="myLink" onclick="alert(0);return false;">myLink</a><br />
<A href="#" name="test" onclick='document.getEleme
</BODY>
</HTML>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
I tried to get around that by executing the click() of the anchor in the onclick of the table row.
ASKER
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(ur l).click() ;
}
What I have below doesn't work.
function SeePic(url) {
document.getElementById(ur
}
Maybe try this? Replace "myLink" with the id of the <a> tag. Hope that helps.
function SeePic(url) {
var theLink = document.getElementById("m yLink");
theLink.href = url;
theLink.click();
}
function SeePic(url) {
var theLink = document.getElementById("m
theLink.href = url;
theLink.click();
}
ASKER
The id is what is getting passed to the function.
Eg. SeePic("MyLink")
Eg. SeePic("MyLink")
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(ur l).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(ur l);
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.
<script type="text/javascript">
function SeePic(url) {
document.getElementById(ur
}
</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(ur
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.
ASKER
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.
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.
Oh, heh ... glad you got what you wanted.
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[