為了改善您的使用體驗,本網站正在進行維護,部分功能暫時無法使用。若本站的文件無法解決您的問題,想要向社群發問的話,請到 Twitter 上的 @FirefoxSupport 或 Reddit 上的 /r/firefox 發問,我們的社群成員將很快會回覆您的疑問。

搜尋 Mozilla 技術支援網站

防止技術支援詐騙。我們絕對不會要求您撥打電話或發送簡訊,或是提供個人資訊。請用「回報濫用」功能回報可疑的行為。

了解更多

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.