我想爲url位置創建一個變量,並根據輸入更改文本。例如,對於bill.google.com,變量的值就是賬單。例如.google.com,變量的值就是示例。我不知道如何訪問網址中的文字。幫幫我?在javascript/jquery中訪問URL?
0
A
回答
1
0
0
你看着window.location的?
- location.hostname返回虛擬主機的域名
- location.pathname返回當前頁面的
- location.port的路徑和文件名返回網絡的端口主機(80或443)
- location.protocol返回使用的Web協議(http://或https://)
+0
w3fools?真? – martriay 2013-02-25 22:27:52
2
location.hostname.split('.')[0]
會給你你正在尋找什麼。
+4
如果它是http://foo.bar.baz.com – AlienWebguy 2013-02-25 22:27:52
+0
好問題。很想看到更多用例考慮的答案。 – 2013-02-25 22:35:05
0
這樣的事情會讓你關閉。 備註:未測試太多。
var _url = location.hostname;
var _reg = /(?:http[s]*\:\/\/)*(?:www\.)*(.*?)\.(?=[^\/]*\..{2,5})/i;
var result = _url.match(_reg);
console.log(result);
相關問題
- 1. 訪問URL
- 2. URL訪問htaccess
- 3. Rails URL訪問
- 4. 訪問URL傭工routes.rb中
- 5. 「訪問」PHP中的URL
- 6. 保護URL訪問在Magento
- 7. 在Swift 3中訪問UIWebView的URL
- 8. Grafana在URL中傳遞訪問令牌
- 9. 在Spring Security中使用params訪問URL
- 10. 避免在AngularJS中直接訪問URL
- 11. 在父組件中訪問URL參數
- 12. 在Windows Mobile中訪問url 6
- 13. 在AngularJs的routeProvider中訪問url 1
- 14. 在Spring MVC中404'd的訪問URL
- 15. 在Oracle Forms/OC4J中訪問URL參數
- 16. 無法訪問URL
- 17. Solr + Jelastic訪問URL
- 18. 循環訪問url
- 19. 訪問URL參數
- 20. 用Java訪問URL
- 21. 訪問URL重寫
- 22. 直接URL訪問
- 23. 如何存儲一個URL並在Greasemonkey中訪問一個URL
- 24. 在Aweber生成的URL字符串中訪問URL變量
- 25. 通過訪問控制功能訪問url的具體訪問
- 26. 更改URL並阻止訪問舊URL
- 27. 無法訪問鏈接而不在URL中添加問號
- 28. 訪問IFrame的父URL
- 29. 需要登錄url訪問
- 30. 訪問基於URL的API
您需要解析[window.location.hostname](https://developer.mozilla.org/en-US/docs/DOM/window.location)。 – Blazemonger 2013-02-25 22:23:29