(I keep forgetting this part of the forum is here).

This is rather peculiar...this works just fine...

<tr onclick="gohere('?a=content&amp;q=edit&amp;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&amp;q=edit&amp;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?

    Because it's an incomplete statement. It's "window.location.href"

      I seem to recall that 'window' is not always needed (anymore). However, I added it and it doesn't solve the problem. 😉

        Comment out the alert and see what it does

          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...

            Ummm...can't delete posts anymore...

              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.

                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.

                  12 days later

                  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..

                    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...

                      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

                        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 🙂

                          a year later

                          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

                            Write a Reply...