仅包含查询字符串的相对URL [英] Relative URL containing just the querystring

查看:107
本文介绍了仅包含查询字符串的相对URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个页面中有一些链接,只需要改变当前URL的查询字符串部分。



例如,当前页面是:



http://demo.com/bigreport?page=13



,我想链接到

http://demo.com/bigreport?page= 14



我可以使用< a href =?page = 14>下一步< / a> 作为相关链接?



我很惊讶地发现它可以在Chrome中使用。我从来没有见过它在任何地方被记录或提及,所以我很想知道是否有人使用这个,并且如果有更广泛的浏览器支持的话。

解决方案

进一步的研究显示< a href =?page = 14>下一个< / a> a有效的相对URL。



它被记录为WHATWG网址的一部分spec
http://url.spec.whatwg.org/#relative-state



新网址会继承基本URL的方案,主机,端口和路径。



经过测试可以使用:


  • Chrome

  • IE 7


I have some links in a page which only need to change the querystring portion of the current URL.

E.g. the current page is:

http://demo.com/bigreport?page=13

and I want to link to

http://demo.com/bigreport?page=14

Can I use <a href="?page=14">Next</a> as a relative link for this?

I was surprised to find it works in Chrome. I've never seen it documented or mentioned anywhere, so I'm keen to know if anyone uses this, and if there is wider browser support.

解决方案

Further research reveals that <a href="?page=14">Next</a> is a valid relative URL.

It's documented as part of WHATWG's URL spec http://url.spec.whatwg.org/#relative-state

The new URL will inherit the base URL's scheme, host, port and path.

Tested to work on:

  • Chrome
  • IE 7

这篇关于仅包含查询字符串的相对URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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