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 7682537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:35:28+00:00 2026-05-31T18:35:28+00:00

I already read these methods as alternative for unsafeWindow. But I still can’t get

  • 0

I already read these methods as alternative for unsafeWindow. But I still can’t get it works to use the Recaptcha object without unsafeWindow.
My code using unsafeWindow is (this code works fine):

var myscript= document.createElement('script');
myscript.setAttribute('src','http://www.google.com/recaptcha/api/js/recaptcha_ajax.js');
document.body.appendChild(myscript);
Recaptcha = unsafeWindow.Recaptcha; 
Recaptcha.create(theKey,"recaptcha_widget_div",{theme:"red"});

I tried this with no luck:

//after script inject
Recaptcha = location.assign("javascript:Recaptcha();void(0)");
Recaptcha.create(theKey,"recaptcha_widget_div",{theme:"red"});

What did I do wrong with the location hack?

Note that I want the code to be usable in a Chrome content script, too.

  • 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-05-31T18:35:30+00:00Added an answer on May 31, 2026 at 6:35 pm

    location.assign() loads a new page; “poofing” away the script and any variables like Recaptcha.

    In this case, go ahead and use unsafeWindow. It’s not really that big a deal unless you know a webmaster is targeting Greasemonkey scripts.

    It’s even less dangerous in this case, because you are adding the recaptcha code. The target page isn’t.


    Update:
    The OP indicated that this is to work in Chrome content scripts too. In that case, inject both parts like so:

    function addJS_Node (text, s_URL) {
        var D                                   = document;
        var scriptNode                          = D.createElement ('script');
        if (text)       scriptNode.textContent  = text;
        if (s_URL)      scriptNode.src          = s_URL;
    
        var targ = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;
        targ.appendChild (scriptNode);
    }
    
    addJS_Node (null, 'http://www.google.com/recaptcha/api/js/recaptcha_ajax.js');
    
    //-- Might need a delay here, but probably not.
    addJS_Node ('Recaptcha.create(theKey,"recaptcha_widget_div",{theme:"red"});');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've already read the gcc manpage, but I still can't understand the difference between
I already read the datasheet and google but I still don't understand something. In
I've already read this question and this question and this , but none of
I have already read all the previous similar posts but I couldn't find a
I've already read through the similar questions on this topic, but none of them
I've read several of the posts on stack overflow already about this topic, but
I already read many article about this issue in here, SO. I just want
I already read this trick in the cookbook: http://book.cakephp.org/2.0/en/models/model-attributes.html#usetable Now I would like to
Scenario Having already read a post on this on the same site, which didn't
I've already read that the if statement in scala always returns an expression So

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.