2015-06-17 65 views
0

今天在公司網站上發現了一個破碎的鏈接,經過一番挖掘,這裏是我發現的:一個簡單的JS函數,在主HTML頁面的網站導航中打開FAQ.aspx頁面。JavaScript window.open()和破損的URL

function openFAQ() { 
     window.open(location.protocol + "help/FAQ.aspx", "null", "width=750, height=800, resizable=1, scrollbars=1, location=0, directories=0, status=no, menubar=no, toolbar=no"); 
} 

該網站動態拼湊在一起。從主頁面(主Web應用程序)

http://example.com/index.aspx

的鏈接常見問題 - 適用於正確的URL爲

http://example.com/help/FAQ.aspx

如果我瀏覽到

http://example.com/userpages/settings.aspx

菜單仍然可用,但是當點擊FAQ時,它會生成fo lrow URL:

http://example.com/userpages/help/FAQ.aspx

"~/help/FAQ.aspx"不能像src或href那樣工作。不知道如何得到這個工作。在此先感謝

回答

2

window.open("/help/FAQ.aspx"....)應該做的伎倆

+0

哈哈,哇,謝謝。只是好奇,是'/'的JavaScript表示根的方式?是〜/'更多的HTML /終端的東西? –

+1

好問題。它是一個與根相關的url,我相信它實際上是在HTML規範中,而不是JavaScript,儘管我沒有看。例如,你可以在HTML中使用'Help Link',它可以以同樣的方式工作。 '〜'是ASP.Net服務器端的東西,並且表示應用程序正在運行的文件系統上的文件夾。 – gaiazov

1

我想這應該工作,

function openFAQ() { 
      window.open(window.location.hostname+ "/help/FAQ.aspx", "null", "width=750, height=800, resizable=1, scrollbars=1, location=0, directories=0, status=no, menubar=no, toolbar=no"); 
    } 

location.protocol provides the protocol used, e.g., http:, https: etc 
location.hostname provides the hostname, e.g., www.mysite.com 
+0

感謝您的回答和解釋! –

+0

不客氣! –