搜索 | 用户支持

防范以用户支持为名的诈骗。我们绝对不会要求您拨打电话或发送短信,及提供任何个人信息。请使用“举报滥用”选项报告涉及违规的行为。

详细了解

Modify URL in address bar with Javascript

  • 4 个回答
  • 3 人有此问题
  • 2 次查看
  • 最后回复者为 AAronoff

more options

I was using a bookmarklet in Firefox that modified the URL in the address bar to switch the page view in Gmail from text to HTML after "Show original" was selected for a particular message:

javascript:window.location=window.location.href.replace("view=om&th","view=lg&msg");

This bookmarklet no longer works.

Is there any way to allow Javascript to access the URL in the address bar?

TIA and regards, Andy

I was using a bookmarklet in Firefox that modified the URL in the address bar to switch the page view in Gmail from text to HTML after "Show original" was selected for a particular message: javascript:window.location=window.location.href.replace("view=om&th","view=lg&msg"); This bookmarklet no longer works. Is there any way to allow Javascript to access the URL in the address bar? TIA and regards, Andy

所有回复 (4)

more options

If I look at Gmail then I see the &v parameter, so maybe try that. Maybe also try not to depend on the order of parameters and split them over more replace calls. I don't know about the 'lg' value (view=lg) as I'm not seeing it in the page source.

  • javascript:void(location.href=location.href.replace("&v=om","&v=c").replace("",""));
more options

FOA, thanks for your reply.

I don't think my problem has been understood.

The Javascript in my first message is correctly constructed. It worked for well over a year in Firefox and it works correctly in IE 11. The problem is not the Javascript. It's Firefox, which appears to have been hardened to refuse access to the URL in the address bar by Javascript in a bookmarklet. (I also tried it in Safe Mode, with no success.)

Are you able to modify the URL in the address bar via Javascript from a Firefox 55.0.3 (Windows 32-bit) bookmarklet? If not, Is there any way to allow this access via about:config?

regards, Andy

more options

OK, that looks like a CSP issue where the website only allows to run scripts from their own website (self).

Unfortunately Firefox applies CSP rules to bookmarklets and thus you can't run these.

You can run the JavaScript code in the Web Console as a workaround.

I don't know whether NoScript can bypass CSP restrictions for bookmarklets.

more options

> that looks like a CSP issue

I'm no longer sure what the issue is.

I uninstalled Firefox and installed previous versions. That had no effect.

I created a brand new profile. That had no effect, either.

A bookmarklet worked for a long time and then suddenly stopped working. (It continues to work in IE 11.)

I checked the bookmarklet in Firefox 55.0.3 on another Windows 7 PC. It didn't work there, either.

I don't understand why this bookmarklet stopped working in Firefox.

Thanks for trying to help.