انتقال به سایت دیگر

تمرین آسان 866 visibility link download flag

با استفاده از جاوااسکریپت برنامه ای بنویسید که کاربر بتواند آدرس وبسایتی را وارد کرده و بلافاصله به آدرس وارد شده منتقل شود

👨‍💻 2 ساعت قبل کاربر ناشناس این تمرین رو مشاهده کرد

reply 6

visibility
<!DOCTYPE html>
<html>
<head>
<title>Redirect</title>
</head>

<body>

<input type="text" id="site" placeholder="آدرس سایت را وارد کنید">
<button onclick="goToSite()">برو</button>

<script>
function goToSite() {
  var url = document.getElementById("site").value;
  window.location.href = url;
}
</script>
</body>
</html>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
      
    </style>
</head>
<body>
    <h1>entegal be sait</h1>
    <button onclick="Address()">vurud be sait</button>
    </form>
    <script>
        let Address=()=>{
            let adres=prompt('lotfan adres ra vared konid:'); 
            url='http://'+adres;
            window.location.href=url;
             }
        
    </script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body{
            display: flex;
            justify-content: center;
        }
    </style>
</head>
<body id="bod">
    <form action="#">
        <input type="text" id="web" value="https://">
        <input type="button" value="btn"  onclick="address()">
    </form>
    
    <script>
        let address = () => {
            let web_address = document.getElementById("web").value;
            window.open(web_address);
        }
    </script>   
</body>
</html>
<!DOCTYPE html>
<html lang="fa">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>انتقال به وب‌سایت</title>
    <script>
        function redirectToWebsite() {
            const url = document.getElementById('website-input').value;

            // بررسی اینکه آیا URL معتبر است یا خیر
            if (url) {
                // اگر URL با http:// یا https:// شروع نمی‌شود، آن را اضافه می‌کنیم
                if (!url.startsWith('http://') && !url.startsWith('https://')) {
                    alert("لطفاً URL را با http:// یا https:// آغاز کنید.");
                    return;
                }
                // انتقال به URL وارد شده
                window.location.href = url;
            } else {
                alert("لطفاً یک آدرس وب‌سایت وارد کنید.");
            }
        }
    </script>
</head>
<body>
    <h1>انتقال به وب‌سایت</h1>
    <input type="text" id="website-input" placeholder="آدرس وب‌سایت را وارد کنید">
    <button onclick="redirectToWebsite()">انتقال</button>
</body>
</html>

ارسال جواب

جوابت را با Markdown بنویس و ثبت کن

×
بستن