如果 window.location.href 有“sometext”里面 - 这样做
目前正在研究使用 ajax 进行分页的东西。我想要做的是将诸如referal=3之类的内容添加到某些链接的末尾,然后当他们转到该链接时,我将插入一个带有窗口位置的后退按钮,例如:
用户使用ajax分页,转到页面3 我会将 ?ref=3 添加到链接或其他内容的末尾,这样它就会像这样:
http://foo.com/somepage/?ref=3
(不确定这是否是一种正确的方法)
然后用户单击该链接,我将在该页面上附加一个带有该链接的后退按钮。
因此,当他们使用生成的按钮返回主页时,window.location.href 将是:
http://foo.com?ref=3
这个想法是,当他们单击后退按钮时, ajax 分页将加载到第 3 页。
我不知道如何解释这一点,但是有人知道我将如何执行依赖于 window.location.href 的条件语句吗?
Currently working on something which uses ajax for some pagination. What I'm looking to do is add something like referal=3 to the end of some links then when they go to that link I'll insert a back button with the window location for example:
User uses the ajax pagination, goes to page 3 I'll add ?ref=3 to the end of the link or something so it would like this this:
http://foo.com/somepage/?ref=3
(not sure if that's a corrent way of doing it)
Then the user clicks that link and I'll append a back button on that page with that link.
So when they go back to the homepage using the generated button the window.location.href will be:
http://foo.com?ref=3
The idea is that when they click that back button, the ajax pagination will load to page 3.
I'm not sure how else to explain this, but does anyone know how I would go about doing a conditional statement dependant on the window.location.href?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要查找 url 是否包含某个字符串:
To find a if the url contains some string:
您可以使用此函数获取查询字符串的部分内容:
然后您可以通过以下方式获取字符串形式的值:
您还可以使用
parseInt()
获取数字形式:You can use this function to get parts of the query string:
Then you can get the value as a string by:
You can also get it as a number by using
parseInt()
:我不确定我完全理解你想要做什么,但听起来你想研究使用 location.hash 属性。
使用 jQuery 插件,例如 hashchange,您可以将 ajax 调用添加到浏览器历史记录中。此外,所有页面都可以添加书签。这是一个相当广泛的主题,但我提供的链接应该可以帮助您入门。
I'm not sure I fully understand what you want to do, but it sounds like you want to look into using the location.hash property.
Using a jQuery plugin, such as hashchange, you can add ajax calls to the browsers history. Also, all pages will be bookmarkable. It's a pretty broad subject, but the link I provided should get you started.