473,795 Members | 2,983 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="JavaS cript" type="text/JavaScript">
function disco() {
if( confirm('are you sure?') ) {
window.location ="http://wwww.google.com ";
}
}
</script>
</head>
<body>
<a href="#" onClick="javasc ript:disco()">D &eacute;connexi on</a></body>
</html>
Jul 23 '05 #1
10 5438
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="JavaS cript" 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="javasc ript:disco()">D &eacute;connexi on</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="JavaS cript" type="text/JavaScript">
function disco() {
if( confirm('are you sure?') ) {
window.location ="http://wwww.google.com ";
}
}
</script>
</head>
<body>
<a href="#" onClick="javasc ript:disco()">D &eacute;connexi on</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="JavaS cript" 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="javasc ript:disco()">D &eacute;connexi on</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.or g/>
[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="JavaS cript" type="text/JavaScript">
function disco() {
if( confirm('are you sure?') ) {
window.location ="http://wwww.google.com ";
}
}
</script>
</head>
<body>
<a href="#" onClick="javasc ript:disco()">D &eacute;connexi on</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="JavaS cript" 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="javasc ript:disco()">D &eacute;connexi on</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();">Googl e</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*****@agrico reunited.com>
comp.lang.javas cript FAQ - http://jibbering.com/faq

Jul 23 '05 #7
Grant Wagner wrote:
Mick White wrote:
window.confir m 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, "recommende d" 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="JavaS cript" 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&eacut e;connexion</a></body>
</html>
Lee <RE************ **@cox.net> wrote in message news:<ce******* *@drn.newsguy.c om>...
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="JavaS cript" type="text/JavaScript">
function disco() {
if( confirm('are you sure?') ) {
window.location ="http://wwww.google.com ";
}
}
</script>
</head>
<body>
<a href="#" onClick="javasc ript:disco()">D &eacute;connexi on</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.confir m 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, "recommende d" would be more
accurate.


Well, no, a second parameter for the confirm() method isn't "recommende d" 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*****@agrico reunited.com>
comp.lang.javas cript FAQ - http://jibbering.com/faq

Jul 23 '05 #10

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

Similar topics

4
18878
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 defined this in a frameset called index.htm. Each frame is loaded with a specific page: top:title.htm, left:menu.htm and mainframe:start.htm. So far so good...
3
4581
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 following code from an external javascript source file, dynamically created with PHP document.write('<a href="javascript:void(0);"
10
8797
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 can with tables. thanks, ~peter
5
10886
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 works fine if I click to open in > the same window, but if I click the browser option to open in a > new window, the new window tries to open the href URL (the > onClick function does get executed, but seems to be ignored). > ...
21
2002
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 and no cross-browsers solutions and all of that we know, but they have told me they have seen that before and how then the annoying pop-up windows work? . . .
14
37167
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 new blank window.. // (NOT in a pop-up, a regular new window..) can you do this?? thank you..
5
7546
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 IE. I link within a page and display individual divisions of that page, manipulating their visibility and display styles with an onClick function. As long as I explicitly click a link to progress, it works with browsers I've tried.
18
3350
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 the image. The desired behavior is that when the pop-up is invoked, I want the underlying window to stay put. I don't have this problem when I run the code on my local computer but I do have it when I run the code on geocities.
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10438
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9042
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7540
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.