Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 重定向到html中的网站以获取按钮_Javascript_Html_Redirect - Fatal编程技术网

Javascript 重定向到html中的网站以获取按钮

Javascript 重定向到html中的网站以获取按钮,javascript,html,redirect,Javascript,Html,Redirect,我正在创建一个带有“同意”和“不同意”按钮的HTML启动页。当用户单击“同意”按钮时,我无法重定向到URL 示例 <head> <meta http-equiv="Pragma" content="no-cache"> <meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <title> TITLE </title> <script>

我正在创建一个带有“同意”和“不同意”按钮的HTML启动页。当用户单击“同意”按钮时,我无法重定向到URL

示例

<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>

标题
函数submitAction(){
var link=document.location.href;
var searchString=“redirect=”;
var equalIndex=link.indexOf(searchString);
var-url=“”;
如果(document.forms[0]。操作==“”){
var url=window.location.href;
var args=新对象();
var query=location.search.substring(1);
var pairs=query.split(“&”);
对于(变量i=0;i=0){
equalIndex+=searchString.length;
重定向URL=“”;
重定向URL+=link.substring(equalIndex);
}
如果(重定向URL.length>255)
redirectUrl=redirectUrl.substring(0255);
document.forms[0]。redirect_url.value=redirectUrl;
document.forms[0]。buttonClicked.value=4;
document.forms[0]。提交();
}
函数拒绝()
{
警报(“您将无法访问系统!”);
}
函数loadAction(){
var url=window.location.href;
var args=新对象();
var query=location.search.substring(1);
var pairs=query.split(“&”);

对于(var i=0;i我将使用窗口。位置,请参阅本页查看示例:

在HTML中,您可以使用:

onclick=“returnsubmitAction();”


并在函数submitAction()的末尾写入返回true;以取消提交或返回false;以允许提交。

在JavaScript中,使用
window.location.assign(URL)
方法,例如

function redirect(url)
{
window.location.assign(url);
}