Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8898547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:38:22+00:00 2026-06-15T00:38:22+00:00

I’m writing a Greasemonkey script that I’m trying to use in Chrome and Firefox.

  • 0

I’m writing a Greasemonkey script that I’m trying to use in Chrome and Firefox. I know you can’t use unsafewindow in Chrome like you can in Firefox, so I’ve been attempting to use jS-uris like in the answer for: Greasemonkey, Chrome and unsafeWindow.foo().

when I try the following:

location.assign("javascript:var tutu = 'oscar';");
location.assign("alert('1:' + tutu);");
alert('2:' + tutu);

I receive an error showing that “tutu” is undefined. Obviously what I’m not understanding is the scope of these variables. I need to make global functions and variables for what I’m working on. What am I not doing correctly?

EDIT: Actually I think the problem isn’t what I’m trying (unless it is, in which case please tell me) but the page I’m writing the script for looks is messing with URLS to keep them from going to anything but a relative URI.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T00:38:23+00:00Added an answer on June 15, 2026 at 12:38 am

    In Chrome, there is a delay after the location.assign calls (they may run in separate threads), so the tutu var isn’t defined when the alert() fires and the whole code throws an exception. (Also, as trinity said, the alert needs to be prefaced with javascript:.)

    You could use a timer like so:

    location.assign("javascript:var tutu = 'oscar';");
    setTimeout (
        function () {location.assign("javascript:console.log('1:' + tutu);"); }
        , 666
    );
    

    But, I think you’ll agree that’s a spot of bother.

    Trying to do page-scope javascript with location.assign will get cumbersome for all but the shortest/simplest code.

    Set, reset, and/or run lots of page-scope javascript using Script Injection:

    function setPageScopeGlobals () {
        window.tutu     = 'Oscar';
        window.globVar2 = 'Wilde';
        window.globVar3 = 'Boyo';
    
        alert ('1:' + tutu);
    
        window.useGlobalVar = function () {
            console.log ("globVar2: ", globVar2);   
        };
    }
    
    //-- Set globals
    addJS_Node (null, null, setPageScopeGlobals);
    
    //-- Call a global function
    addJS_Node ("useGlobalVar();");
    
    //-- Standard-ish utility function:
    function addJS_Node (text, s_URL, funcToRun, runOnLoad) {
        var D                                   = document;
        var scriptNode                          = D.createElement ('script');
        if (runOnLoad) {
            scriptNode.addEventListener ("load", runOnLoad, false);
        }
        scriptNode.type                         = "text/javascript";
        if (text)       scriptNode.textContent  = text;
        if (s_URL)      scriptNode.src          = s_URL;
        if (funcToRun)  scriptNode.textContent  = '(' + funcToRun.toString() + ')()';
    
        var targ = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;
        targ.appendChild (scriptNode);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to understand how to use SyndicationItem to display feed which is
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.