-3

I am creating an HTML splash page with agree and disagree buttons. I am having trouble redirecting to a URL when the user clicks the agree button.

Example

<head>
<meta http-equiv="Pragma" content="no-cache">
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<title> TITLE </title>
<script>

function submitAction(){
  var link = document.location.href;
  var searchString = "redirect=";
  var equalIndex = link.indexOf(searchString);
  var redirectUrl = "";

  if (document.forms[0].action == "") {
  var url = window.location.href;
  var args = new Object();
  var query = location.search.substring(1);
  var pairs = query.split("&");
      for(var i=0;i<pairs.length;i++){
          var pos = pairs[i].indexOf('=');
          if(pos == -1) continue;
          var argname = pairs[i].substring(0,pos);
          var value = pairs[i].substring(pos+1);
          args[argname] = unescape(value);
      }
      document.forms[0].action = args.switch_url;       
  }       
  if(equalIndex >= 0) {
        equalIndex += searchString.length;
        redirectUrl = "";
        redirectUrl += link.substring(equalIndex);
  }
  if(redirectUrl.length > 255)
  redirectUrl = redirectUrl.substring(0,255);
  document.forms[0].redirect_url.value = redirectUrl;
  document.forms[0].buttonClicked.value = 4;
  document.forms[0].submit();
}

function reject()
{
alert("You will not be able to access the system!");
}


function loadAction(){
  var url = window.location.href;
  var args = new Object();
  var query = location.search.substring(1);
  var pairs = query.split("&");
  for(var i=0;i<pairs.length;i++){
      var pos = pairs[i].indexOf('=');
      if(pos == -1) continue;
      var argname = pairs[i].substring(0,pos);
      var value = pairs[i].substring(pos+1);
      args[argname] = unescape(value);
  }
  document.forms[0].action = args.switch_url;

}

</script>
</head>    
<body style="background-color:#FFFFFF;" topmargin="50" marginheight="50" 
        onload="loadAction();"> <form method="post"> <input TYPE="hidden" 
NAME="buttonClicked"     SIZE="16" MAXLENGTH="15" value="0"> <input TYPE="hidden"  

NAME="redirect_url" SIZE="255"   MAXLENGTH="255" VALUE=""> <input TYPE="hidden" 

NAME="err_flag" SIZE="16" MAXLENGTH="15"   value="0">

<div style="text-align:center;">
<p><IMG SRC="./11.jpg"></p>
<p><img src="1223.jpg" alt="Wireless Print" title="Wireless Print" /></p>
</div>

<p align=center><iframe src="./aup.html" width="90%" height="500" scrolling="auto"> 

</iframe></p>

<div style="text-align:center;">
  <input style="font-weight:bold;height:75px;width:200px;font-size:24pt;" type="button"    

name="Reject" value="Reject" class="button" onclick="reject();">
<input style="font-weight:bold;height:75px;width:200px;font-size:24pt; margin-left:75px;"  

type="button" name="Submit" value="Accept" class="button" onclick="submitAction();">
</div>

<div style="text-align:center; margin:1em 1em; margin: 1em 0 auto 1em">
<div style="font-weight:bold; text-align:center; color:#FFFFFF; background-color:#634099;   

width:90%; margin: 0 auto; font-family:Verdana,Arial;">
 <br /> Example <br /><br />
</div>

</form>
</body>
</html>
Nick Binnet
  • 1,910
  • 7
  • 33
  • 49
Bobbi
  • 37
  • 1
  • 1
  • 6

2 Answers2

1

I will use Window.location, see this page to see examples:

http://www.w3schools.com/js/js_window_location.asp

In HTML you could use:

onclick="return submitAction();"

and at the end of function submitAction() write return true; to cancel submission or return false; to permit submission.

Alex Abreu Mulet
  • 118
  • 1
  • 1
  • 9
1

In JavaScript, use window.location.assign(URL) method, e.g.

function redirect(url)
{
window.location.assign(url);
}
imulsion
  • 8,820
  • 20
  • 54
  • 84