[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 673
  • Last Modified:

Javascript Error in Onclose Handler

I got this script of Dynamic Drive and have been trying to customise the script.

This is the original


<script type="text/javascript">

var agreewin=dhtmlmodal.open("agreebox", "iframe", "surveyinfo.asp", "UBA Survey", "width=590px,height=250px,center=1,resize=1,scrolling=0", "recal")

agreewin.onclose=function(){ //Define custom code to run when window is closed
      var theform=this.contentDoc.getElementById("eula") //Access form with id="eula" inside iframe
      var yesbox=theform.eulabox[0] //Access the first radio button within form
      var nobox=theform.eulabox[1] //Access the second radio button within form
      if (yesbox.checked==true)
            alert("You are now being redirected to our online survey\nThank you for taking time out to do this survey")
            
            else if (nobox.checked==true)
            //alert("You didn't agree to the terms")
            return true //Allow closing of window in both cases            
}
</script>

And this is the line that I have added "window.location.href="./polls/default.asp""

I want this to riderect and open a new windows but the script generates an error message before redirecting and it redirects to the parent window.

<script type="text/javascript">

var agreewin=dhtmlmodal.open("agreebox", "iframe", "surveyinfo.asp", "UBA Survey", "width=590px,height=250px,center=1,resize=1,scrolling=0", "recal")

agreewin.onclose=function(){ //Define custom code to run when window is closed
      var theform=this.contentDoc.getElementById("eula") //Access form with id="eula" inside iframe
      var yesbox=theform.eulabox[0] //Access the first radio button within form
      var nobox=theform.eulabox[1] //Access the second radio button within form
      if (yesbox.checked==true)
            alert("You are now being redirected to our online survey\nThank you for taking time out to do this survey")
            
            else if (nobox.checked==true)
            //alert("You didn't agree to the terms")
            return true //Allow closing of window in both cases
      window.location.href="./polls/default.asp"
            
}

</script>

Could someone help me out here ?
0
souldj
Asked:
souldj
  • 2
1 Solution
 
neeraj523Commented:
should be like this

this should open default.asp page in a new window before redirecting..
<script type="text/javascript">
	var agreewin=dhtmlmodal.open("agreebox", "iframe", "surveyinfo.asp", "UBA Survey", "width=590px,height=250px,center=1,resize=1,scrolling=0", "recal")
	agreewin.onclose=function(){ //Define custom code to run when window is closed
    var theform=this.contentDoc.getElementById("eula") //Access form with id="eula" inside iframe
    var yesbox=theform.eulabox[0] //Access the first radio button within form
    var nobox=theform.eulabox[1] //Access the second radio button within form
    if (yesbox.checked==true)
	{
		alert("You are now being redirected to our online survey\nThank you for taking time out to do this survey")
		window.open('./polls/default.asp','pop')
	}
    //alert("You didn't agree to the terms")
    return true //Allow closing of window in both cases
	}
</script>

Open in new window

0
 
souldjAuthor Commented:
Could you also add a cookie so that on the default page, the script does not load again.
0
 
neeraj523Commented:
yes... u can do that..
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now