简体   繁体   English

href中的current_url()与“”

[英]current_url() vs. “ ” in an href

I want to have links that allow for page refreshing and setting href="" seems reasonable. 我想拥有允许页面刷新的链接,并且设置href=""似乎合理。

I'm using Codeigniter (PHP framework) which has a function current_url() so I could also write href="<?=current_url()?>" but I won't do that unless there's some reason href="" is bad. 我正在使用具有功能current_url() Codeigniter(PHP框架),因此我也可以编写href="<?=current_url()?>"但除非有某些原因,否则我不会这样做, href=""不好。

Am I missing anything on the usefulness of href="<?=current_url()?>" ? 我是否缺少有关href="<?=current_url()?>"有用性的内容?

note: I imagine most frameworks/languages have something similar to current_url() so my question is more general about the downsides of writing href="" . 注意:我想大多数框架/语言都具有与current_url()类似的东西,所以我的问题是关于编写href=""的缺点的一般性问题。

The only difference is when you have a base tag in your head. 唯一的区别是您的头部带有基本标签。 Otherwise they should be identical. 否则,它们应该相同。

With a <base href='www.test.com'> in your head then href='' will resolve to relative to the base. 头部带有<base href='www.test.com'> ,href =''将相对于基数进行解析。

I read that some browsers had bugs with href="" in the past. 我了解到,过去某些浏览器存在href=""错误。 Even though new browsers shouldn't have a problem with href=""; 即使新的浏览器应该对href =“”没问题; I'd go with href="<?=current_url()?>" to avoid running into bugs with older browsers. 我会使用href="<?=current_url()?>"以避免遇到旧版浏览器的错误。

I can't imagine any downside, really. 我真的无法想象有什么缺点。 It's what I'd do. 这就是我要做的。

If you're curious about other options, you could also use the Javascript method window.location.reload(); 如果您对其他选项感到好奇,也可以使用Javascript方法window.location.reload(); for the same effect. 具有相同的效果。

考虑到SEO,链接到您自己的页面可能会有好处,但我不知道有什么好处/缺点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM