Javascript浏览器历史记录(Javascript Browser History)
我正在编写一个已经变成无限循环的应用程序。 它从页面A开始,然后在按下按钮时重定向到页面B,在幕后运行一些JavaScript后再次自动重定向到页面A.
这变成了无限循环。 有没有办法从两页前检查浏览器历史记录? 如果我可以这样做,我可以使用当前浏览器窗口URL检查该URL,并在页面A的按钮按下时停止重定向功能(如果两者相等)。
任何其他想法也会有所帮助。
I am writing an application that has turned into an infinite loop. It starts out on Page A, it then redirects to Page B on button press which automatically redirects to Page A again after running some JavaScript behind the scenes.
This turns into an infinite loop. Is there any way to check the browser history from two pages ago? If I can do that I can check that URL with the current browser window URL and stop the redirect functionality on the button press of Page A if the two are equal.
Any other ideas would be helpful as well.
原文:https://stackoverflow.com/questions/33816015
最满意答案
我碰巧使用
j-toker
CommonJS包,它在内部使用jQuery
的ajax
API。 jQuery与服务器端呈现不兼容,因为它需要一个document
元素来加载自身,它只存在于浏览器中,而不存在于服务器中。 解决方案尚未到手,但正如J-Toker的作者所指出的那样 ,他即将发布一个涵盖服务器端渲染案例的新库。因此,对于遇到类似错误的任何人,请检查您是否正在使用
jquery
或依赖于jquery
任何其他包,或者需要具有document
DOM元素,并尝试使用服务器端呈现安全替代方案。I happened to be using the
j-toker
CommonJS package which internally usesjQuery
'sajax
API. jQuery is incompatible with server side rendering since it needs adocument
element to load itself, and it only exists in the browser, not in the server. The solution is not yet at hand, but as J-Toker's author has indicated, he's about to release a new library that covers the case of server side rendering.So, to anyone encountering a similar error, check if you are using
jquery
or any other package that in turns depends onjquery
, or requires having adocument
DOM element, and try using a server-side-rendering-safe alternative.
相关问答
更多-
您通过在module.exports属性上定义这些方法来公开这些方法。 例如,假设您有一个文件reactExports.js var iWontGetThere = 'I am in this module only'; module.exports = { React: React, ReactDOM: ReactDOM } 现在在另一个文件中,您可以要求使用这些方法并使用它们,如下所示: var React = require('reactExports').React; var SweetComp ...
-
Browserify允许您创建自定义转换,有一个很好的示例,说明如何在以下链接创建转换。 https://github.com/substack/browserify-handbook#transforms 使用process.cwd()替换$CWD的示例似乎是OP创建所需转换的良好起点。 在潜在的未来死链接的情况下,这是一个例子。 var through = require('through2'); module.exports = function (file) { return throug ...
-
好的,这很简单: PhotoRoot = require('photo_root') 应该 PhotoRoot = require('./photo_root') ok that was simple: PhotoRoot = require('photo_root') should be PhotoRoot = require('./photo_root')
-
它似乎是椭圆形的问题,是browserify的依赖。 请参阅https://github.com/indutny/elliptic/issues/30 希望这很快得到解决。 编辑:它实际上可能是browserify的一个问题。 我会尝试恢复到8.1.2,看看是否有帮助。 It looks like it is an issue with elliptic, a dependency of browserify. See https://github.com/indutny/elliptic/issues/3 ...
-
我认为你可能遇到的问题是你正在尝试安装和使用的npm模块是ES6 JS模块。 从你的错误日志中,我猜你正在使用Browserify来加载你的JS模块。 开箱即用的IIRC Browserify仅支持Common JS模块,这意味着您必须通过Babel或Babelify(babel的browserify变换)等工具来运行JS,以使用module.exports语法将该ES6模块转换为ES5模块。 I think the issue you might be having is that the npm mod ...
-
每个模块都依赖于反应,路由器应该将后面的配置添加到自己的软件包中。 "browserify-shim": { "react": "global:React" }, "browserify": { "transform": [ "browserify-shim" ] }, every module rely on react like react-router should add the behind config to its own package. "browseri ...
-
问题在于browserify-rails缓存依赖关系,我的application.js仍然是指先前卸载的模块。 在这种情况下,我应该在上面的违规行中发现了formsy-react-components 。 通过运行rake tmp:cache:clear修复。 The issue was that browserify-rails caches dependencies and my application.js was still referring to a previously uninstalled ...
-
我碰巧使用j-toker CommonJS包,它在内部使用jQuery的ajax API。 jQuery与服务器端呈现不兼容,因为它需要一个document元素来加载自身,它只存在于浏览器中,而不存在于服务器中。 解决方案尚未到手,但正如J-Toker的作者所指出的那样 ,他即将发布一个涵盖服务器端渲染案例的新库。 因此,对于遇到类似错误的任何人,请检查您是否正在使用jquery或依赖于jquery任何其他包,或者需要具有document DOM元素,并尝试使用服务器端呈现安全替代方案。 I happene ...
-
如果Browserify不存在,如何使用Browserify创建新目录?(How to create a new directory with Browserify if it does not exist?)[2021-12-14]
您的两次尝试因各种原因而失败。 使用gulp.dest()第一次尝试失败,因为gulp.dest()返回一个简单的字符流,而gulp.dest()只能处理vinyl对象流。 您需要使用vinyl-source-stream模块将char流转换为vinyl流。 之后, gulp.dest()将工作,并将创建任何尚不存在的文件夹: var browserify = require('browserify'); var source = require('vinyl-source-stream'); brows ... -
jQuery main设置为dist/jquery.js ,因此您可以简单地执行此操作: var jQuery = require('jquery'); jQuery('body').text('hello world'); 请注意,只有在没有全局document属性的情况下,jQuery才会导出其工厂。 当与Browserify一起使用时,有一个,因此导出的不是工厂函数,而是常规jQuery对象。 jQuery has main set to dist/jquery.js, thus you can ...