473,574 Members | 2,722 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

window.location not working

I have a very simple confirm link on a website using the following code:

function confirmNewSuppl ier(){
if(confirm(' Are you sure that you can\'t select a supplier from the
list? \n(Click OK to request a new supplier or Cancel to return to the
Directory)')){
window.location = 'l1stage1.php';
}
}
the link is as follows:

<a href="javascrip t:;" onClick="confir mNewSupplier()"
class="mainText Normal">Creatin g a New Supplier</a>

The alert pops up but it does not redirect

What am i doing wrong???

Jul 23 '05 #1
2 6402
Craig Keightley wrote:
the link is as follows:

<a href="javascrip t:;" onClick="confir mNewSupplier()"
class="mainText Normal">Creatin g a New Supplier</a>

The alert pops up but it does not redirect


Some user agents do some optimization on links and do not change the
location while a link is active, but cache the assignments to location
properties instead. You can watch this in MSIE, while Gecko based
browsers would do what you expected. After executing your function,
the link is executed and "javascript :;" is assigned to the href
property, overwriting what was assigned by your function. Simply
return false in your click event handler to suppress the link's
default action:

<a href="#" onclick="confir mNewSupplier(); return false" ...>...</a>

A better approach that would keep the document working in User Agents
not using JS (or having JS disabled) would be:

function confirmNewSuppl ier(){
return confirm(
' Are you sure that you can\'t select a supplier from the '
+ 'list? \n(Click OK to request a new supplier or Cancel to '
+ 'return to the Directory)'
);
}
....
<a href="l1stage1. php" onclick="return confirmNewSuppl ier()" ...>...</a>

I would prefer another variant that separates code and text:

var oMsg = {
...,
"NewSupCnf" : "Are you sure that you can't select a supplier from the list?\n"
+ "(Click OK to request a new supplier or Cancel to return to the "
+ "Directory) ",
...
}
....
<a href="l1stage1. php" onclick="return confirm(oMsg.Ne wSupCnf)" ...>...</a>

ciao, dhgm
Jul 23 '05 #2
thats great thank you
"Dietmar Meier" <us************ ***@innoline-systemtechnik.d e> wrote in
message news:39******** *****@individua l.net...
Craig Keightley wrote:
the link is as follows:

<a href="javascrip t:;" onClick="confir mNewSupplier()"
class="mainText Normal">Creatin g a New Supplier</a>

The alert pops up but it does not redirect


Some user agents do some optimization on links and do not change the
location while a link is active, but cache the assignments to location
properties instead. You can watch this in MSIE, while Gecko based
browsers would do what you expected. After executing your function,
the link is executed and "javascript :;" is assigned to the href
property, overwriting what was assigned by your function. Simply
return false in your click event handler to suppress the link's
default action:

<a href="#" onclick="confir mNewSupplier(); return false" ...>...</a>

A better approach that would keep the document working in User Agents
not using JS (or having JS disabled) would be:

function confirmNewSuppl ier(){
return confirm(
' Are you sure that you can\'t select a supplier from the '
+ 'list? \n(Click OK to request a new supplier or Cancel to '
+ 'return to the Directory)'
);
}
...
<a href="l1stage1. php" onclick="return confirmNewSuppl ier()" ...>...</a>

I would prefer another variant that separates code and text:

var oMsg = {
...,
"NewSupCnf" : "Are you sure that you can't select a supplier from the
list?\n"
+ "(Click OK to request a new supplier or Cancel to return to
the "
+ "Directory) ",
...
}
...
<a href="l1stage1. php" onclick="return confirm(oMsg.Ne wSupCnf)"
...>...</a>

ciao, dhgm

Jul 23 '05 #3

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

Similar topics

10
14695
by: Scott | last post by:
I'm new to ASP, but I've been programming in VB for several years, and I'm having a few issues with this ASP enhancement I'm working on. I've found ASP to be a lot different than what I'm use to in VB. I've created an ASP interface where a user can select an email group that populates a listbox with those email addresses. If a user sees...
2
4114
by: venkatesh | last post by:
Hi Members, I have used the below mentioned code to open a html page in a new browser. The window size is 200 x 300. In that browser, I've given code to open another browser of the same size. However, this is not happening in IE 5. Can anyone help me solve this problem? Code: Script:
1
1554
by: Tersia Ehlert | last post by:
Hi I have an .NET web application where I redirect a page on submit to a blank page where the code below runs client side. I want to, with this code, refresh two frames - the one my page was opened in and another frame loading a list of items assigned to me. This code was working 100% until we chnaged the site to a secure site (HTTPS) -...
5
7515
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....
2
4392
by: voodoolv | last post by:
So.. I have a javascript that makes a popup with a javscript function in it. The function in the popup after 5 seconds tries to change the "price" field value in the opener window: sourze= "<script type=%20text/javascript%20> function change(){ window.opener.document.forms.price.value=123;}; setTimeout('change()',5000);</script>"; ...
2
8803
by: Dennis Ålund | last post by:
Is it possible to notice a change of window.location.hash without polling? I'm working on a Ajax-platform (yes, inventing the wheel again) and have finished almost everything except the support for back/forward-buttons. The track I'm working on is "hidden frames" to keep state in window.location.hash. I've seen some solutions along this...
8
2477
by: johnsonholding | last post by:
Here is the code for a pop-up window that works in Firefox and not in IE - I get a java error or something, Here is the code : </script> <SCRIPT language="JavaScript" type="text/javascript"> <!-- ; var newwindow = ''
9
2573
by: tshad | last post by:
This was posted before but the message got messed up (all NLs were stripped out for some reason). I have 2 labels that hold the name of different images on my .aspx page. <asp:Label ID="Logo" runat="server"/> <asp:Label ID="CompanyPicture" runat="server"/> I have 2 links that open the windows to preview these images. The previewed...
6
2319
mikewagan
by: mikewagan | last post by:
hello guys, Javascript's been bugging on IE, and i'm trying to search for a solution for this answer but no luck. I have a select box as a navigation element. If a user clicks on an option, it will go to a separate page. This works well in Mozilla, but not in IE. heres my code: <form method="get" action=""> <select name="category"...
1
3155
by: vinpkl | last post by:
hi all i have two dynamic drop downs of dealer id and category id which work properly with window.location var dealerid; function getList(xyz) { window.location='manage_products.php?category_id=' + xyz; }
0
7813
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7736
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...
0
8066
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. ...
1
7826
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...
0
6461
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...
1
5631
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...
0
5305
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...
0
3755
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2251
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

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.