[英]Redirect the page to new webpage
我有one.html和two.html,我的要求是當用戶輸入one.html的url時,應該顯示一個消息“你被重定向到新的網頁”的對話框,用戶可以點擊確定按鈕繼續或者在10秒內,對話框應自動關閉,用戶應重定向到新頁面(two.html)。 請建議。
PS:我能夠在某種程度上得到結果,但問題是我能夠看到one.html及其上的對話框,而用戶不應該看到one.html,只有帶有消息的對話框和ok按鈕應該如果用戶沒有點擊“確定”按鈕,則在10秒后顯示給用戶,它應該重定向到兩個頁面。
將此腳本放在one.html中。 代碼不言自明。
<script>
function redirectToPage2(){
var redirectUrl = "two.html"
message= "You will be redirected to Page 2. Click <a href='"+redirectUrl+"'>here</a> if you are not redirected in 10 seconds.";
$(body).innerHTML=message;
setTimeout(function(){
window.location=redirectUrl;
}, 10000); // will redirect after 10 seconds
}
}
window.onload = redirectToPage2;
</script>
如果你不想看到one.html,你需要另一個頁面 - 比如說three.html。 代碼看起來像這樣。
One.html
<script>
window.onload = "Three.html";
</script>
並將上述代碼放在Three.html中。
如果您的目標只是將one.html的觀看者重定向到two.html,則可以嘗試以下代碼:
<meta http-equiv="refresh" content="0;two.html">
或者如果您計划在重定向之前加載某些內容,請嘗試以下操作:
<script language=javascript>
function redirect(){
// do stuffs
window.location = "two.html";
}
</script>
<body onload="redirect()">
<!-- your content -->
</body>
one.html
<script src="jquery-1.12.2.min.js"></script>
<script>
window.onload = function myFunction() {
if (confirm("Are you sure you want to redirect with two.html page ?") == true) {
window.location.href="two.html";
}
}
</script>
說明:
- 添加此CSS In標頭
<style>
body
{
display:none;
}
</style>
那可能會有所幫助....
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.