Solved

Javascript Error in Onclose Handler

Posted on 2008-06-12
3
651 Views
Last Modified: 2013-11-19
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
Comment
Question by:souldj
  • 2
3 Comments
 
LVL 22

Accepted Solution

by:
neeraj523 earned 500 total points
ID: 21768583
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
 
LVL 1

Author Comment

by:souldj
ID: 21770905
Could you also add a cookie so that on the default page, the script does not load again.
0
 
LVL 22

Expert Comment

by:neeraj523
ID: 21771358
yes... u can do that..
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now