简体   繁体   中英

current_url() vs. “ ” in an href

I want to have links that allow for page refreshing and setting href="" seems reasonable.

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.

Am I missing anything on the usefulness of 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="" .

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.

I read that some browsers had bugs with href="" in the past. Even though new browsers shouldn't have a problem with href=""; I'd go with href="<?=current_url()?>" to avoid running into bugs with older browsers.

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(); for the same effect.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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