锚< a> +链接到基本网址 [英] anchor <a> + Link to base URL

查看:97
本文介绍了锚< a> +链接到基本网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在一个页面上,比如

http://localhost/balibar.co/?dating = dating-articles-and-information



我想将链接到基本网址的链接定位为

http:// localhost / balibar.co



有没有一种方法可以在不对网址进行硬编码的情况下执行此操作?



我试过了:

 < a href =/>< / a> 
< a href =#>< / a>

将有几个域使用此页面,因此我不想对域名进行硬编码if可能。

解决方案

 < head> 
< base href =http://www.google.com/>
< / head>
< body>
< a href => Google?< / a>
< / body>

该链接现在转到google.com



以下是证明:

http:// jsfiddle.net/3wXCJ/



您使用HTML的< base> 标签来指定基础所有使用 href 属性的元素的url。现在,任何具有 href src 属性的标签都是空的,它会自动转到您在默认情况下是基本标记。


If I'm on a page like

http://localhost/balibar.co/?dating=dating-articles-and-information

and I want to have anchor that links to the base URL being

http://localhost/balibar.co

Is there a way to do this without hard coding the URL?

I've tried:

 <a href="/"></a>
 <a href="#"></a>

will have a few domains use this page so I don't want to hard code the domain name if possible.

解决方案

<head>
    <base href="http://www.google.com" />
</head>
<body>
    <a href="">Google?</a>
</body>

That link will now go to google.com

Here is the proof:

http://jsfiddle.net/3wXCJ/

You use HTML's <base> tag to specify the base url for all elements that use the href attribute. Now, any tag with an href or src attribute that is empty, it will automatically go to the url you specified in the base tag by default.

这篇关于锚&lt; a&gt; +链接到基本网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆