Join the AMA (Ask Me Anything) with the Firefox leadership team to celebrate Firefox 20th anniversary and discuss Firefox’s future on Mozilla Connect. Mark your calendar on Thursday, November 14, 18:00 - 20:00 UTC!

This site will have limited functionality while we undergo maintenance to improve your experience. If an article doesn't solve your issue and you want to ask a question, we have our support community waiting to help you at @FirefoxSupport on Twitter and/r/firefox on Reddit.

Search Support

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

Modify URL in address bar with Javascript

  • 4 replies
  • 3 have this problem
  • 2 views
  • Last reply by 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

All Replies (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.