Click to See Complete Forum and Search --> : [RESOLVED] javascript location.href problem...
vaaaska
03-21-2006, 01:32 PM
(I keep forgetting this part of the forum is here).
This is rather peculiar...this works just fine...
<tr onclick="gohere('?a=content&q=edit&id=73');">
<td>Something</td>
</tr>
function gohere(url) {
location.href = url;
}
And this will not - but I return an alert that is correct.
<input type="image" src='imgs/f-edit.gif' title='Edit'
onclick="goherenot('?a=content&q=edit&id=73');" />
function goherenot(url) {
alert(url); // returns exactly what it should...
location.href = url; // just doesn't want to do this...
}
Am I not seeing something obvious here? Any help out there?
JPnyc
03-21-2006, 01:37 PM
Because it's an incomplete statement. It's "window.location.href"
vaaaska
03-21-2006, 01:59 PM
I seem to recall that 'window' is not always needed (anymore). However, I added it and it doesn't solve the problem. ;)
JPnyc
03-21-2006, 02:07 PM
Comment out the alert and see what it does
vaaaska
03-21-2006, 02:08 PM
The alert is only there to show me that it's passing url...it's not really there...
Is there some plausible explanation that when it comes from the table row it's not submitting but when it comes from the image (input) it is - and that is somehow is negating it?
The browser also refreshes on goherenot() but doesn't go to the new location...
khendar
03-21-2006, 11:13 PM
Change the url being passed to goherenot() to http://www.google.com or something. You will probably find that this code is working perfectly - its the php interpretation of the parameters that you are passing in which is broken.
vaaaska
03-22-2006, 05:29 AM
its the php interpretation of the parameters that you are passing in which is broken.
Could you explain this a little more?
But, there is more than one way to skin a cat. Instead, I edited up the CSS to perform the exact same functionality on any link that has the particular class...so, it does work globally now.
arumpfelt
04-03-2006, 11:59 AM
I have exactly the same problem..
don't have any idea why it's not working - in my case there's a problem in IE (Firefox works just fine) - it just does nothing when I try to do this:
onClick="location.href='http://www.google.pl';"
whether I add "window." or not.. it's just dead..
The same functionality works fine in another part of my app.. what's happening ?
I just found out that there is an anchor put over image...maybe that's the problem ?
edit: no.. whether I put onClick on image or text anchor there's nothing happening..
arumpfelt
04-03-2006, 12:14 PM
GOT IT !
ok, here is the solution:
for IE, put in the end of your redirecting script this line:
window.event.returnValue=false;
now it works perfect..
it's documented here:
http://support.microsoft.com/kb/190244/en-us
edit: funny..they say it applies to IE 4.0 & 4.1.. I use 6.0..so this bug seems to come back..
another thing is that I don't use 'href="#"' but 'href="javascript://"'..
sometimes I just hate IE...
MarkR
04-04-2006, 04:46 AM
There is no need to put in the MSIE-specific hack.
The correct way of doing it, is simply returning false from the event handler:
<a href="doesntmatter" onclick="return gohere('/wherever');">blah</a>
<script>
function gohere(where) { window.location = where; return false; }
</script>
That way you don't have two different things "fighting" to send the browser to different places.
Mark
arumpfelt
04-04-2006, 04:58 AM
Thanks Mark, I was getting window.event error in Firefox after inserting what MSIE suggested.
Anyway, your solution is pretty logical, since there shouldnt be any "browser action" after I evaluate my redirection function.
So 'return false;' makes the deal :)
Thank you for your help :)
devyani
07-20-2007, 06:59 AM
Thanks Mark for your help. Even I was facing same problem but didn't know how to fix it. My code too works perfectly fine now after giving "return false" in javascript;
Thanks again
Devyani
PHP Builder
Copyright WebMediaBrands Inc. All Rights Reserved.