JavaScript 中的新页面/转发
我正在制作一个greasemonkey脚本,我想要一个链接来前进并修改当前的html并允许用户单击返回以转到原始页面。
我该怎么做?使用jquery+greasemonkey+javascript。主要针对 Firefox。
-edit- http://jsfiddle.net/ 似乎可以做到这一点。如果您在 html 部分编写随机 html,请单击运行,更改 html,然后再次单击运行。您将能够单击后退/前进以查看输出更改(但 html 输入框保持不变)。我正在使用 Firefox 来查看此内容。这就是我想要的效果
看来魔法是在第 91 行完成的。这是否在框架中提交了表单(也许是结果框架?)并且这导致了历史上的运动?
88 run: function(e) {
89 e.stop();
90 Layout.updateFromMirror();
91 document.id(this.options.formId).submit();
92 this.fireEvent('run');
93 },
I am making a greasemonkey script and i would like a link to go forward and modify the current html and allow the user to click back to go to the original page.
How might i do this? using jquery + greasemonkey + javascript. Targeting firefox mostly.
-edit- http://jsfiddle.net/ seems to do it. If you write random html in the html section, hit run, change the html and hit run again. You'll be able to click back/forward to see the output change (however the html input box stays the same). I am using firefox to view this. Thats the effect i want.
it appears the magic is done on line 91. Is this submitting a form in a frame (perhaps the results frame?) and that is causing the movement in history?
88 run: function(e) {
89 e.stop();
90 Layout.updateFromMirror();
91 document.id(this.options.formId).submit();
92 this.fireEvent('run');
93 },
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道这是否可能,因为浏览器本身负责处理导航历史记录。仅当您访问新页面时才会添加新的历史记录项目。
如果我没记错的话,您希望用户打开/关闭您对页面所做的更改,而不启用/禁用greasemonkey 并重新加载页面。
我认为对此的唯一解决方案是您自己处理。保存您对页面所做的任何更改,以便您可以恢复它并向页面添加一些 UI 以使用户打开或关闭您的更改。
编辑1:
jsfiddle.net 似乎加载了一个新页面来执行此操作。使用 firebug,您可以看到它没有执行任何 AJAX 请求来运行代码,它只是加载一个新页面(可能是同一页面,具有不同的参数,但尽管如此,它正在加载一个页面。)
编辑 2:
是的,也许它正在框架中加载页面。正如您从 HTML 中看到的:
但这并没有改变您的情况。如果您希望逻辑位于 Greasemonkey 脚本中,则无法加载新页面。否则,您应该将网页上传到某个地方,然后将其加载到 iframe 中,并将您要修改的 HTML 传递给它:这绝对不是您想要做的。
I don't know if that is possible at all because it is the browser itself that takes care of the navigation history. A new history item is added only when you visit a new page.
If I am not wrong you would like the user to turn on/off the changes you make to the page without enabling/disabling greasemonkey and reloading the page.
The only solution I see for this is to take care of it yourself. Save any changes you make to the page so that you can restore it and add some UI to the page to make the user turn on or off your changes.
EDIT 1:
It seems that jsfiddle.net loads a new page to do that. Using firebug you can see it is not doing any AJAX request to run the code, it is just loading a new page (maybe the same page, with different parameters, but nevertheless it is loading a page.)
EDIT 2:
Yes, maybe it is loading the page in a frame. As you can see from the HTML:
But this does not change your situation. If you want your logic to be in your greasemonkey script you can't load a new page. Otherwise you should upload a web page somewhere and make it load in an iframe passing it the HTML you want to modify: this is definitely not what you want to do.
听起来您想使用历史记录管理器。您可以跟踪所做的更改并在用户返回时撤消它们,或者可以调用页面刷新函数。
It sounds like you want to use a history manager. You could either track the changes you make and undo them when the user goes back, or possibly call a page refreshing function.