473,743 Members | 2,246 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 5429
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
18859
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
4579
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
8794
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
1995
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
37159
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
7538
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
3347
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
8795
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
9486
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
9344
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9277
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8218
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...
0
6057
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4827
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2195
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.