简体   繁体   English

如何通过JavaScript重定向到URL?

[英]How to redirect to URL by JavaScript?

I have JavaScript code to redirect to URL but it doesn't work. 我有JavaScript代码可以重定向到URL,但是它不起作用。 It will load but no redirect to the URL. 它将加载,但不会重定向到URL。 The page which have this code the content of data for Facebook tab front page. 具有此代码的页面的代码用于Facebook选项卡首页的数据内容。

The script: 剧本:

<script type="text/javascript">
    function newDoc() {
        window.location.assign("http://facebookapp.elarabygroup.com/facebook_login.aspx")
    }
</script>

The page: 这一页:

 <a onclick="newDoc()" >
            <img src="images/glass.png" width="95" height="72" />play now</a>

Try using window.location instead of window.location.assign 尝试使用window.location而不是window.location.assign

For instance this will redirect you to example.com when you click the text. 例如,当您单击文本时,这会将您重定向到example.com。 (Tested in Chrome) (在Chrome中测试)

<html>
    <head>
        <script type="text/javascript">
        function onClick() {
            window.location = "http://example.com";
        }
        </script>
    </head>
    <body>
        <a onclick="onClick()">To example.com!</a>
    </body>
</html>

试试,window.location.href ='http //:www.google.com'它将生成一个新请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM