[SOLVED]Javscript help needed, link using top.location

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
rsmarsha
Forum Contributor
Posts: 242
Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England

[SOLVED]Javscript help needed, link using top.location

Post by rsmarsha »

I have the following link which works fine in everything apart from IE6. In most browsers it takes a value from an adjacent text box and passes that along with the rest of the link to the intended page.

In IE6 it does nothing.

Code: Select all

<a href="javascript://" onClick="top.location='cart.php?xCmd=add&position=<?php echo $cr['productID']; ?>&xFwd=customer.php?xCmd=wlshow&xProd=<?php echo $cr['productID'];?>&qty<?php echo $cr['productID'];?>='+document.getElementById('qty<?php echo $cr['productID'];?>').value" />
Any ideas? help urgently needed and thanks in advance. :)
Last edited by rsmarsha on Wed Aug 15, 2007 9:55 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I would suspect it has something to do with your href.
rsmarsha
Forum Contributor
Posts: 242
Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England

Post by rsmarsha »

Yeah i'm not an expert in javascript, was told to do the link this way to get it to do what i wanted. Works fine in ie7/firefox/opera. Any tips on what to do to fix it?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

1. Listen to what feyd says ;)

2. I use location.replace() instead of location= . Maybe that is the problem.
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Javscript help needed, link using top.location

Post by superdezign »

rsmarsha wrote:

Code: Select all

javascript://
I could see IE choking on that.
rsmarsha
Forum Contributor
Posts: 242
Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England

Post by rsmarsha »

I am listening, but the fact it's a problem with my href, doesn't get me any further. I need to get this one fixed quickly, i'm googling it as well as posting here, tried a few things. A pointer will help. :)


Thanks in advance for any tips. :)

On a side note , like the "A world without IE" site, superdezign. :)
Last edited by rsmarsha on Wed Aug 15, 2007 9:19 am, edited 1 time in total.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

Code: Select all

<a href="javascript:top.location='cart.php?xCmd=add&posit.......' ">
, no onclick
or

Code: Select all

<a href="#" ... 
, and your code for onclick
There are 10 types of people in this world, those who understand binary and those who don't
rsmarsha
Forum Contributor
Posts: 242
Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England

Post by rsmarsha »

That last one has fixed it, thanks VladSun.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

rsmarsha wrote:I am listening, but the fact it's a problem with my href, doesn't get me any further.
It should. It just means use a different one. Whenever your URL begins with 'javascript:' the browser assumes that anything after it is a JavaScript command. Firefox and IE have different error handling techniques, and I'd bet that IE6 just.. chokes.

The JavaScript command '//' would just be a syntax error. Maybe you want 'javascript:void(0)' or use a regular URL, and just add a 'return false' to the end of your onClick.
rsmarsha wrote:On a side note , like the "A world without IE" site, superdezign. :)
:lol:
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

rsmarsha wrote:That last one has fixed it, thanks VladSun.
Note that if you don't use 'return false,' that the browser will still follow the link, which would likely make you navigate to the top of the page every time you click.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

0. Listen to superdezign too :) :) :)
1. In fact, I would never use onclick in an anchor tag in your case - you are overwriting exisitng functionality - the href="javascript:code" param.
There are 10 types of people in this world, those who understand binary and those who don't
rsmarsha
Forum Contributor
Posts: 242
Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England

Post by rsmarsha »

Thanks again all. :)
Post Reply