2013-10-17 36 views
2

我在做一個簡單的重定向來強制用戶使用HTTPS而不是HTTP。我知道有很多縮短newUrl變量的方法,但事實是這個循環在IE8中持續,但在FF中起作用。該網頁的其餘部分甚至沒有加載....但我得到所需的URL,我希望....有誰知道爲什麼window.location在IE8上運行不同?Javascript重定向循環只在IE8上

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

我不知道這會在任何瀏覽器都工作過。 – putvande

+0

https://github.com/SublimeLinter/SublimeLinter – tenub

+0

建設性評論... putvande! – user2891480

回答

4

您必須使用兩個=比較字符串:

if (location.protocol == "http:") { 
+0

...或可以說*三*等於符號。 – RichieHindle

+0

謝謝....現在有點愚蠢,但2等於我如果ealier認爲我不斷交換之間!=和==,然後到上面。 – user2891480