首页 \ 问答 \ 带有Hashtags的Popstate?(Popstate with Hashtags?)

带有Hashtags的Popstate?(Popstate with Hashtags?)

我有一个使用AJAX动态将内容加载到div中的站点。

执行此操作的链接是具有href =“#”的锚点和用于触发AJAX的onclick事件。

当我点击回来时,这让我没有历史记录,所以如果我加载一个页面,然后另一个页面然后单击返回,它什么都不做。

代码的基本版本是这样的:

<script type="text/javascript">
function loadXMLDoc(url)
{
<!-- Load XML Script here. -->
}
</script>

</head>

<body>

<div id="myDiv">

<!-- Target div. -->

</div>

<a href="#1" onclick="loadXMLDoc('1.txt')">Click Me.</a>

<a href="#2" onclick="loadXMLDoc('2.txt')">Click Me.</a>

<a href="#3" onclick="loadXMLDoc('3.txt')">Click Me.</a>

</body>

我想知道的是,我可以给每个链接一个不同的“#”然后使用一个popstate处理程序来调用相应的事件,所以如果我点击链接1,2和3然后开始点击后退按钮,它我会回到2然后再等1 ..

我打算使用history.js并在loadXML脚本中开始使用pushstate,但我认为整个操作历史记录有点脏和不可靠。

我在思考正确的方向还是有更好的方法?

目前我的所有链接都使用“#”,以便在加载更多内容时弹回页面顶部,但我希望能够尽可能返回。

任何帮助都会很棒。


I have a site that uses AJAX to dynamically load content into a div.

The links to do so are anchors with href="#" and an onclick event to trigger the AJAX.

This leaves me without a history when I click back, so if I load one page, then another and click back, it does nothing.

A basic version of the code is this:

<script type="text/javascript">
function loadXMLDoc(url)
{
<!-- Load XML Script here. -->
}
</script>

</head>

<body>

<div id="myDiv">

<!-- Target div. -->

</div>

<a href="#1" onclick="loadXMLDoc('1.txt')">Click Me.</a>

<a href="#2" onclick="loadXMLDoc('2.txt')">Click Me.</a>

<a href="#3" onclick="loadXMLDoc('3.txt')">Click Me.</a>

</body>

What I would like to know is, can I give each link a different "#" and then use a popstate handler to call the appropriate event, so if I click link 1, 2 and then 3 and then start hitting the back button, it'll go back to 2 and then 1 etc..

I was going to use history.js and start using pushstate in the loadXML script but I think the whole manipulating history thing is a bit dirty and unreliable.

Am I thinking on the right lines or is there a better way?

Currently all my links just use "#" so that it pops back to the top of the page when loading more content but I'd like to be able to go back if possible.

Any help would be great.


原文:https://stackoverflow.com/questions/16146034
更新时间:2024-02-11 17:02

最满意答案

你不应该使用内部框架类,而是依赖公共API ...

var textbox = grid.SelectedRow.Cells[1].Controls[0] as TextBox;

you are not supposed to use internal framework classes, rather rely on the public api...

var textbox = grid.SelectedRow.Cells[1].Controls[0] as TextBox;

相关问答

更多
  • 没有。 考虑以下: LERP(x++,1,2); c代码也可能会有两次增加x的副作用[它是未定义的@ phresnel],而c#代码是完美定义的,并且只会增加x一次。 结果也可能不同,因为[宏]中的第a和第二个可能具有不同的值,因为它可能在第一个中增加。 no. consider the following: LERP(x++,1,2); The c code might also have a side effect of increasing x twice [it is undefined as me ...
  • 使用这些标志 BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance 此操作不需要GetProperty标志。 您可能也想添加Static 。 注意:您可以将标志与|结合使用 ,因为它们的整数值是2的幂。 看到这个答案 。 注意 (为了回应拉尔曼和小腿对安全问题的反思) 总有一种方法可以编写不好或危险的代码。 这取决于你是否做到。 反思不是常规的做事方式,而是面向特殊工具的编程,如o / r-mappers或分析工具。 反思 ...
  • if ((latch_state & 0x1) != 0) 应该管用。 通常,不评估为布尔值的C ++条件与0进行隐式比较,“true”表示表达式不为0。 if ((latch_state & 0x1) != 0) should work. Normally, C++ conditions which don't evaluate to a boolean are doing an implicit comparison to 0, with 'true' being that the expressi ...
  • 如果你使用ffmpeg很好,你可能想看看这个问题的答案。 If you are fine with using ffmpeg, you may want to look at answers to this question.
  • 您尝试的C#等价物中的各种代码似乎与原始C ++代码不对应。 这是一个直接可编译的翻译,假设您在某处定义了“isVowel”: using System.Collections.Generic; public enum TKeyIdentity { _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _1, _2, _3 } public class TraverseKeyPaths { public readonly ...
  • 尝试这个 Dim m As MenuItem = TryCast(sender, MenuItem) audioDevice = (IIf(m.Index>0, filters.AudioInputDevices(m.Index-1), Nothing)) IIf功能MSDN文档 由于不推荐使用IIf函数,请使用这样的方法 If m.Index>0 Then audioDevice = filters.AudioInputDevices(m.Index-1) Else audioDev ...
  • 在C中,只需将指针传递给第k个项(即array+k ),就可以“制作”一个没有前k个元素的array+k ,因为C中的数组通过传递第一个元素的位置来传递(这种“新”数组根本不是新的,因为它将引用“原始”数组的相同元素)。 在C#中,这不起作用,因为数组不是作为指向连续内存的指针处理的; 如果你想快速修复,你可以创建一个新数组,使用Array.Copy将元素从第k个复制到最后,然后将这个新数组传递给递归函数,但这很慢,如果没有用,算法修改数组的元素(修改不会反映在其他数组中,因为它们现在是副本)。 一个更好的 ...
  • 在转换此代码时,最好的方法是什么? 这取决于您的目标和应用。 如果您计划跨产品/版本共享代码,那么您最好拥有一个API来抽象平台详细信息并为每个平台分离代码。 我应该专注于转换使用MonoTouch库吗? iOS(或MonoTouch)不支持WPF API。 因此,您最接近的方法是查看MonoTouch提供的iOS API(即在查看第三方库之前查看已有的内容)。 您可以通过使用iOS CoreGraphics (通常与旧的System.Drawing模型非常相似)找到类似的功能。 对于位图图像,您应该阅读C ...
  • 你不应该使用内部框架类,而是依赖公共API ... var textbox = grid.SelectedRow.Cells[1].Controls[0] as TextBox; you are not supposed to use internal framework classes, rather rely on the public api... var textbox = grid.SelectedRow.Cells[1].Controls[0] as TextBox;
  • Marshal.PtrToStringAnsi()是将IntPtr转换为字符串所需的。 IntPtr持有char* , Marshal.PtrToStringAnsi()是你的家伙。 但是,你已经尝试过但没有成功。 所以我怀疑你的问题更为根本。 也许你在互操作边界的两边处理大结构的方式上存在二进制不匹配。 这是互操作的一部分,其中不同的工具表现不同。 应始终使用out参数返回结构。 将本机代码更改为: __declspec(dllexport) int compute_calc(int opt, const ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)