如果window.location.href里面有'sometext'

编程入门 行业动态 更新时间:2024-10-27 20:24:55
如果window.location.href里面有'sometext' - 这样做(if window.location.href has 'sometext' inside - do this)

目前正致力于使用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?

最满意答案

要查找url是否包含某些字符串:

if (document.location.href.search("ref=3")!=-1){ alert('got ref=3'); }

To find a if the url contains some string:

if (document.location.href.search("ref=3")!=-1){ alert('got ref=3'); }

更多推荐

本文发布于:2023-07-28 19:09:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1308221.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:location   window   sometext   href

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!