views:

157

answers:

3

Hi I'm using following function to goto a proxypage on a click of href. for first click to the href it works fine. but second click onwards the code does not call the window.event.returnValue=true; statement while if i use debugger it works as expected.

function CallDownloadProxy(url)
{
  //debugger;
  try
  {
   window.location = url;
   window.event.returnValue=true;
}

  catch (err)
  {
    alert(err.description );
  }

}

kindly assist if anybody knows about this

A: 

Returning false also prevents the default action and works for every browser.

function CallDownloadProxy(url) {
   window.location.href = url;
   return false;
}

I'm wondering why you use JS instead of a link. And what do you mean with "second click"? Why would somebody need to click the link twice?

slosd
A: 

It seems you need to do something like this right after setting returnValue:

 // e comes from event handler parameter
 if (e && e.stopPropagation) //if stopPropagation method supported
  e.stopPropagation()
 else
  event.cancelBubble=true; // for IE

EDIT: must be in this case

window.event.cancelBubble=true;

Thevs
this is not working
Ashutosh Singh
A: 

As far as I know, location = "..." and location.href = "..." are the equivalent of location.assign("..."). Which means the subsequent lines of code may be evaluated by the browser, but as soon as the JavaScript yeilds, the browser will unload your document, and load the new URL regardless of whether you cancel your onclick event, or prevent it from bubbling.

If you require a repeatable action, you should target your link to another frame or something...

I've no idea what your question means with respect to going to a proxy page (?!) and working the first time but not the second. What second time? If the user clicks back? If the user clicks refresh? If the user double clicks? If the user comes back tomorrow? What does it mean!!??

Lee Kowalkowski
I reckon it's pretty bad etiquette to down vote an answer without providing a reason. Would you like our help or not?
Lee Kowalkowski