2013-04-04 50 views
-3

我正在創建一個帶有同意和不同意按鈕的HTML初始頁面。當用戶點擊同意按鈕時,我無法重定向到某個網址。重定向到一個按鈕的HTML網站

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

2014-02-13 12:07:50

回答

1

我會用window.location的,看到這個頁面看到的例子:

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

在HTML中你可以使用:

的onclick = 「return submitAction();」

並在函數結束處submitAction()寫入返回true;取消提交或返回false;以允許提交。

1

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

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