To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > Misc Help > ClientSide Technologies

ClientSide Technologies Discuss HTML/CSS/Javascript, and any other client-side technologies, here.

Reply
 
Thread Tools Rate Thread Display Modes
Old 03-21-2006, 01:32 PM   #1
vaaaska
Construction zone
 
Join Date: Apr 2004
Posts: 1,848
[RESOLVED] javascript location.href problem...

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

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

PHP Code:
<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.

PHP Code:
<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?
vaaaska is offline   Reply With Quote
Old 03-21-2006, 01:37 PM   #2
JPnyc
Administrator
 
Join Date: Jan 2005
Posts: 963
Because it's an incomplete statement. It's "window.location.href"
__________________
PHP builder Online Community Manager

JPnyc is online now   Reply With Quote
Old 03-21-2006, 01:59 PM   #3
vaaaska
Construction zone
 
Join Date: Apr 2004
Posts: 1,848
I seem to recall that 'window' is not always needed (anymore). However, I added it and it doesn't solve the problem.
vaaaska is offline   Reply With Quote
Old 03-21-2006, 02:07 PM   #4
JPnyc
Administrator
 
Join Date: Jan 2005
Posts: 963
Comment out the alert and see what it does
__________________
PHP builder Online Community Manager

JPnyc is online now   Reply With Quote
Old 03-21-2006, 02:08 PM   #5
vaaaska
Construction zone
 
Join Date: Apr 2004
Posts: 1,848
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...

Last edited by vaaaska; 03-21-2006 at 02:11 PM.
vaaaska is offline   Reply With Quote
Old 03-21-2006, 11:13 PM   #6
khendar
Senior Member
 
Join Date: Nov 2003
Location: Adelaide, Australia
Posts: 243
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.
khendar is offline   Reply With Quote
Old 03-22-2006, 05:29 AM   #7
vaaaska
Construction zone
 
Join Date: Apr 2004
Posts: 1,848
Quote:
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.

Last edited by vaaaska; 03-22-2006 at 08:04 AM.
vaaaska is offline   Reply With Quote
Old 04-03-2006, 11:59 AM   #8
arumpfelt
Junior Member
 
Join Date: Apr 2006
Posts: 4
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..

Last edited by arumpfelt; 04-03-2006 at 12:04 PM.
arumpfelt is offline   Reply With Quote
Old 04-03-2006, 12:14 PM   #9
arumpfelt
Junior Member
 
Join Date: Apr 2006
Posts: 4
GOT IT !

ok, here is the solution:
for IE, put in the end of your redirecting script this line:

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

Last edited by arumpfelt; 04-04-2006 at 04:07 AM.
arumpfelt is offline   Reply With Quote
Old 04-04-2006, 04:46 AM   #10
MarkR
Senior Member
 
Join Date: Jul 2004
Location: Oxford, England
Posts: 1,983
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:

Code:
<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
MarkR is offline   Reply With Quote
Old 04-04-2006, 04:58 AM   #11
arumpfelt
Junior Member
 
Join Date: Apr 2006
Posts: 4
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
arumpfelt is offline   Reply With Quote
Old 07-20-2007, 06:59 AM   #12
devyani
Junior Member
 
Join Date: Jul 2007
Posts: 1
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
devyani is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 09:55 AM.






Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.