Why is this short and simple function not working in MSIE?

A

a-ok

function confirmDelete(id, title) {
confirmation=confirm('Delete " '+title+' "?');
if (confirmation) {
window.location='delete.php'; // NOTHING HAPPENS
}
}

Tried it with window.location.href, tried putting alert() before and
after window.location (alert box pops up but it won't redirect)...
works ok in Firefox and Opera. Doesn't work in MSIE 6 on XP SP1.




TIA
 
L

Lee

(e-mail address removed) said:
function confirmDelete(id, title) {
confirmation=confirm('Delete " '+title+' "?');
if (confirmation) {
window.location='delete.php'; // NOTHING HAPPENS
}
}

Tried it with window.location.href, tried putting alert() before and
after window.location (alert box pops up but it won't redirect)...
works ok in Firefox and Opera. Doesn't work in MSIE 6 on XP SP1.

Give it a full url.
 
A

a-ok

There is no full url... except http://localhost/ :)

But I found the problem...

I called the function from an onclick event in a link <a> tag but the
href value containted another javascript call, like

<a href="javascript: somefunction()"
onclick="confirmDelete()">Delete</a>

Apparently, this doesn't work in MSIE if the function confirmDelete()
calls the window.location method.



Dumb ass MSIE...



rgds.
 
L

Lee

(e-mail address removed) said:
There is no full url... except http://localhost/ :)

But I found the problem...

I called the function from an onclick event in a link <a> tag but the
href value containted another javascript call, like

<a href="javascript: somefunction()"
onclick="confirmDelete()">Delete</a>

Apparently, this doesn't work in MSIE if the function confirmDelete()
calls the window.location method.


Dumb ass MSIE...

Be that as it may, you should [almost] never do either of those things.
Avoid the javascript: pseudo-protocol unless the javascript code that
it defines returns the new HTML content of the page, and don't change
the window.location in the middle of an event that is intended to change
the page content.
 
G

Grant Wagner

There is no full url... except http://localhost/ :)

But I found the problem...

I called the function from an onclick event in a link <a> tag but the
href value containted another javascript call, like

<a href="javascript: somefunction()"
onclick="confirmDelete()">Delete</a>

Apparently, this doesn't work in MSIE if the function confirmDelete()
calls the window.location method.

No, it has no problems with that at all.

<a href="noJS.html"
onclick="
if (!confirmDelete())
somefunction();
return false;
">Delete</a>
-- OR --
<a href="noJS.html"
onclick="
!confirmDelete() && someFunction();
return false;
">Delete</a>
<script type="text/javascript">
function confirmDelete() {
if (confirm('Do you really want to delete blah?')) {
location = 'about:blank';
return true;
}
return false;
}
Dumb ass MSIE...

Do you blame the hammer when you hit your thumb too?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top