473,403 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

window.location and opera

hi guys,

this code works fine in IE but doesnot work in opera. the page just
reloads to test.html# in opera.

can anyone help? thanks.

-----------------------------------------------------------------------

<html>
<head><script language="JavaScript" type="text/JavaScript">
function disco() {
if( confirm('are you sure?') ) {
window.location="http://wwww.google.com";
}
}
</script>
</head>
<body>
<a href="#" onClick="javascript:disco()">D&eacute;connexion</a></body>
</html>
Jul 23 '05 #1
10 5380
Ivo
"K. S." wrote
this code works fine in IE but doesnot work in opera. the page just
reloads to test.html# in opera.

<html>
<head><script language="JavaScript" type="text/JavaScript">
function disco() {
if( confirm('are you sure?') ) {
window.location="http://wwww.google.com";
Try setting the location's href property directly:
window.location.href="http://wwww.google.com";
}
}
</script>
</head>
<body>
<a href="#" onClick="javascript:disco()">D&eacute;connexion</a>
onclick="disco();"

without the "javascript:" bit and preferably with an ending semicolon for
good manners.
</body></html>


I don't have opera but it 's always the same little things..
HTH
Ivo
Jul 23 '05 #2
K. S. wrote:
hi guys,

this code works fine in IE but doesnot work in opera. the page just
reloads to test.html# in opera.

can anyone help? thanks.

-----------------------------------------------------------------------

<html>
<head><script language="JavaScript" type="text/JavaScript">
function disco() {
if( confirm('are you sure?') ) {
window.location="http://wwww.google.com";
}
}
</script>
</head>
<body>
<a href="#" onClick="javascript:disco()">D&eacute;connexion</a></body>
</html>


Probably because you are not returning false from the onclick. Also, you
do not need the javascript: and that may also be part of Opera not
working with it:

<a href="noScript.html" onclick="disco();return false">.........</a>
Jul 23 '05 #3
K. S. wrote:
hi guys,

this code works fine in IE but doesnot work in opera. the page just
reloads to test.html# in opera.

can anyone help? thanks.

-----------------------------------------------------------------------

<html>
<head><script language="JavaScript" type="text/JavaScript">
function disco() {
if( confirm('are you sure?') )
window.confirm method requires two arguments

function disco(){
if(confirm('are you sure?','') ){.....

Mick

{ window.location="http://wwww.google.com";
}
}
</script>
</head>
<body>
<a href="#" onClick="javascript:disco()">D&eacute;connexion</a></body>
</html>

Jul 23 '05 #4
K. S. wrote:
this code works fine in IE but doesnot work in opera. the page just
reloads to test.html# in opera.

can anyone help? thanks.


Make it Valid HTML[1] first, and remove the "javascript:" nonsense,
see the FAQ[2].
PointedEars
___________
[1] <http://validator.w3.org/>
[2] <http://jibbering.com/faq/>
Jul 23 '05 #5
Lee
K. S. said:

hi guys,

this code works fine in IE but doesnot work in opera. the page just
reloads to test.html# in opera.

can anyone help? thanks.

-----------------------------------------------------------------------

<html>
<head><script language="JavaScript" type="text/JavaScript">
function disco() {
if( confirm('are you sure?') ) {
window.location="http://wwww.google.com";
}
}
</script>
</head>
<body>
<a href="#" onClick="javascript:disco()">D&eacute;connexion</a></body>
</html>

Since your onClick event handler does not return false, you're
telling the page to both:
a) set the location to google.com
b) follow the URL specified in the HREF value to "test.html#"

Browsers will do one or the other. Since following the link is
the primary function of the <A> tag, that's what most browsers
will do. If that's not what you want, return false:

onclick="disco();return false"


Jul 23 '05 #6
Mick White wrote:
K. S. wrote:
hi guys,

this code works fine in IE but doesnot work in opera. the page just
reloads to test.html# in opera.

can anyone help? thanks.

-----------------------------------------------------------------------

<html>
<head><script language="JavaScript" type="text/JavaScript">
function disco() {
if( confirm('are you sure?') )


window.confirm method requires two arguments

function disco(){
if(confirm('are you sure?','') ){.....


No, it really doesn't: <url:
http://devedge.netscape.com/library/...w.html#1201914
/>

It actually doesn't even require one argument in Internet Explorer: <url:
http://msdn.microsoft.com/workshop/a...ds/confirm.asp
/>

Although Gecko-based browsers generate an error and Netscape 4 presents a
confirm dialog that says "undefined" if you attempt to call confirm() without
any arguments. Regardless, that wasn't his problem. He explicitly said that
the link "reloads <the url>#". This is a major hint that he's got the
following code:
<a href="#" onClick="javascript:disco()">D&eacute;connexion</a></body>


and that he isn't returning false from the onclick event:

<a href="#" onclick="disco();return false;">Google</a>

Of course, this isn't really what he wants because regardless of what the
user chooses the link won't be followed. What he wants is for the link to
force the user to answer yes or no, so:

<script type="text/javascript">
function disco() {
return confirm("Are you sure?");
}
</script>
<a href="http://wwww.google.com" onclick="return disco();">Google</a>

Is what he really wants.

Now you've got a fully functional link regardless of whether the browser
supports or has JavaScript enabled. And if JavaScript is enabled, it will
prompt the user "Are you sure?". Clicking the affirmative button will result
in true being returned to the event and the HREF will be followed. Clicking
the negative button will result in false being returned to the event and the
HREF will not be followed.

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #7
Grant Wagner wrote:
Mick White wrote:
window.confirm method requires two arguments

No, it really doesn't: <url:
http://devedge.netscape.com/library/...w.html#1201914
/>

It actually doesn't even require one argument in Internet Explorer: <url:
http://msdn.microsoft.com/workshop/a...ds/confirm.asp
/>
Well, "require" is probably the wrong word, "recommended" would be more
accurate.
Although Gecko-based browsers generate an error and Netscape 4 presents a
confirm dialog that says "undefined" if you attempt to call confirm() without
any arguments. Regardless, that wasn't his problem. He explicitly said that
the link "reloads <the url>#".


The answer to this problem was already pointed out to the OP.

Mick

Jul 23 '05 #8
Thanks all ...

Lee's post was the one that made it work.

for reference, here is the code that works:

----------------------------------------------------------------------
<html>
<head><script language="JavaScript" type="text/JavaScript">
function disco() {
if( confirm('are you sure?','') ) {
window.location.href="http://www.google.com";
}
}
</script>
</head>
<body>
<a href="#" onClick="disco();return false;">D&eacute;connexion</a></body>
</html>
Lee <RE**************@cox.net> wrote in message news:<ce********@drn.newsguy.com>...
K. S. said:

hi guys,

this code works fine in IE but doesnot work in opera. the page just
reloads to test.html# in opera.

can anyone help? thanks.

-----------------------------------------------------------------------

<html>
<head><script language="JavaScript" type="text/JavaScript">
function disco() {
if( confirm('are you sure?') ) {
window.location="http://wwww.google.com";
}
}
</script>
</head>
<body>
<a href="#" onClick="javascript:disco()">D&eacute;connexion</a></body>
</html>

Since your onClick event handler does not return false, you're
telling the page to both:
a) set the location to google.com
b) follow the URL specified in the HREF value to "test.html#"

Browsers will do one or the other. Since following the link is
the primary function of the <A> tag, that's what most browsers
will do. If that's not what you want, return false:

onclick="disco();return false"

Jul 23 '05 #9
Mick White wrote:
Grant Wagner wrote:
Mick White wrote:

window.confirm method requires two arguments

No, it really doesn't: <url:
http://devedge.netscape.com/library/...w.html#1201914
/>

It actually doesn't even require one argument in Internet Explorer: <url:
http://msdn.microsoft.com/workshop/a...ds/confirm.asp
/>


Well, "require" is probably the wrong word, "recommended" would be more
accurate.


Well, no, a second parameter for the confirm() method isn't "recommended" either. In both of the
links shown above confirm() takes exactly one parameter (well, in the case of IE, even that one
parameter is optional). The Gecko DOM is the same: <url:
http://www.mozilla.org/docs/dom/domr...2.html#1016997 />

Oh, it just occurred to me, you're thinking of prompt(), which does take a second (optional)
parameter.

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #10
Grant Wagner wrote:


Oh, it just occurred to me, you're thinking of prompt(), which does take a second (optional)
parameter.
By golly, you're right, I am. Sorry to the OP for the confusion.
Mick

Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Erik-Jan Bakker | last post by:
Hi I am not a javascript expert and I have a problem that the guru's in this newsgroup probably can solve quickly. ;-) I've made a webpage with three frames: top, left and mainframe. I...
3
by: sentinel | last post by:
Hi all, I'm trying to reload a frame from a pop-up, but really cannot figure this out. Within my index.htm file, I make a link to call a pop-up frame with a javascript function that calls the...
10
by: Peter Altenberg | last post by:
is there some way to make the positioning of a layer (div) so that it is centered in the window. so even when you resize the window it stays centered? i would like to do this with CSS just like you...
5
by: Mike | last post by:
In my previous post, I wrote: > ... > GOAL: (very simple) Provide a hyperlink which, when clicked, > calls a javascript function which opens a new URL. > ... > PROBLEM: The following code...
21
by: Albretch | last post by:
Hi, client wants for a window with no toolbars to open (technical and 'esthetical' reasons) after the window, user clicks on, is being closed. I told them about security settings in browsers...
14
by: Frances Del Rio | last post by:
I'm trying to open a url in a new window while pg loads (but NOT in a pop-up..) I need to do sthg like // while pg is loading.. window.location ='page.html' // but I need this to open in a...
5
by: spam_me_ not | last post by:
I already understand that one cannot disable a browser's forward and back functions. This is a situation where I have code working in Mozilla V1.6 and would like something similar for Opera and...
18
by: len.hartley | last post by:
Hi, I am trying to pop-up a window when the user clicks on an image. The problem is that when the user clicks on the image and the window pops up OK, but the window underneath also proceeds to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.