By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,341 Members | 1,709 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,341 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Lee
a-**@consultant.com 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.

Jul 23 '05 #2

P: n/a
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.

Jul 23 '05 #3

P: n/a
Lee
a-**@consultant.com 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.

Jul 23 '05 #4

P: n/a
<a-**@consultant.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
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;
}
</script>
Dumb ass MSIE...


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

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.