2

ユーザーが HTTP ではなく HTTPS を使用するように強制する単純なリダイレクトを行っています。newUrl 変数を短縮する方法はたくさんあることは知っていますが、これは IE8 では継続的にループしますが、FF では機能します。ページの残りの部分は読み込まれません....しかし、私が望んでいる目的のURLを取得します.... IE8でwindow.locationが異なる理由を知っている人はいますか??

<script language="JavaScript">
    if (location.protocol = "http:") {
        var newUrl = "https://";
        newUrl += location.hostname;
        newUrl += ":64040";
        newUrl += location.pathname;
        newUrl += location.search;
        // redirect
        window.top.location = newUrl;
    }
</script>
4

1 に答える 1

4

文字列を比較するには、2 つの = を使用する必要があります。

if (location.protocol == "http:") {
于 2013-10-17T17:06:07.217 に答える