10
A
回答
28
你可以這樣說:
if(document.URL.indexOf("foo_page.html") >= 0){
...show your message
}
+3
可能想要'> = 0'。 – Syntactic 2010-05-17 15:44:06
+0
好的地方,謝謝。編輯。 – GShenanigan 2010-05-17 15:44:45
2
下面會顯示一個警告框如果URL是一樣的東西http://example.com/foo_page.html:
if(location.pathname=="/foo_page.html") alert('hey!');
1
var index = document.location.lastIndexOf("/");
var filename = document.location.substr(index);
if(filename.indexOf("foo_page.html")>-1){
alert("OK");
}
1
您可以使用document.location
弄清楚訪客所在的網址。
試試這個:
<script type="text/javascript">
var currentPage = document.location.href.substring(document.location.href.lastIndexOf("/")+1, document.location.href.length);
</script>
你「當前頁」變量現在應該包含你正在瀏覽的網頁的名稱。你可以用它來選擇一個動作。
0
var loc = window.location.pathname.split("/"),
size = loc.length
alert(loc[size])
給你最後一部分被「/」分開大部分時間的HTML,PHP或任何文件。但我會用你身體上的課程來認識你的位置。或者只是檢查你想要做什麼的元素是否存在於頁面上。在你執行這樣的功能之前
function example(element) {
if(getElementById(element).length) {
// now you are sure that a element exists on the page
}else{
return false; //if not just do nothing
}
}
example("myId")
相關問題
- 1. 包含javascript操作的URL
- 2. 如果URL等於此,請執行此操作嗎?
- 3. 如果動態URL是特定的,請執行此操作嗎?
- 4. 如果URL包含#
- 5. 如果代碼給出錯誤,請執行此操作。javascript
- 6. 如果URL包含字符串「字符串A」或「字符串B」或「字符串C」,請執行此操作
- 7. 如果正則表達式有結果並且結果包含單詞「wordpress」,請執行此操作
- 8. .htaccess auto_prepend_file如果url包含
- 9. URL請求URI - 如果URL包含X do Y else do Z PHP
- 10. 如果url包含以下內容,請不要顯示此代碼
- 11. 如果$ url包含空格,PHP:imagecreatefromjpeg($ url)不起作用。
- 12. 如果URL包含特殊字符使用javascript重定向到給定的URL
- 13. 如果URL中包含X和URL不包含Ÿ
- 14. 重寫規則但不包含URL如果URL包含
- 15. 如果文件包含此文本,請使用PHP進行檢查
- 16. 如果進程正在運行,請執行此操作,否則請執行此操作
- 17. 如果首先點擊任何列表項目,請執行此操作,否則請執行此操作
- 18. Http POST請求URL包含'['
- 19. 使Grails操作僅適用於包含
- 20. 如果字符串包含其他,如果它不包含 - Javascript
- 21. 如何創建表包含此結果?
- 22. 如果URL包含單詞,請在iframe中隱藏div
- 23. 如果URL包含單詞,請隱藏div
- 24. 如果div沒有包含某個類的div,請執行一些操作。 JQuery
- 25. 如果字符串在數組中,請執行此操作?
- 26. 如果我的網頁是空白的,請執行此操作
- 27. jQuery,如果var = 1,請執行此操作
- 28. PHP如果file_get_contents失敗,請執行此操作
- 29. (PHP)如果變量等於HTML輸出,請執行此操作
- 30. 如果class是'current',那麼請執行此操作
請提供更多詳細信息。 – SLaks 2010-05-17 15:39:35