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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:41:27+00:00 2026-06-06T18:41:27+00:00

Im looking to inject a variable into a page before a method is run.

  • 0

Im looking to inject a variable into a page before a method is run. The situation is as follow

CUSTOM JS CAN GO HERE

my.var = 'cake';
my.function();

I dont have access to be able to modify the page directly, however there is a content area at the top of the page I can add some JS if i need to. Basically i need to overwrite the my.var variable with something else before my.function() is run. Is there a way to do this? (the site is running jQuery 1.4.2.

Thanks
Dan

  • 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-06T18:41:29+00:00Added an answer on June 6, 2026 at 6:41 pm

    Basically i need to overwrite the my.var variable with something else before my.function() is run. Is there a way to do this?

    var oldfunction = my.function;
    my.function = function () {
        my.var = "whatever you want";
        oldfunction.apply(this, arguments);
    }
    

    This is, of course, if my or my.function isn’t overwritten by the code you can’t modify directly before the call to my.function (as my.var is).

    For example, in the following scenario:

    ///your code goes here
    
    ///code you cannot modify below
    var my = {};
    my.function = something;
    my.var = 'cake';
    my.function();
    

    what you want is impossible (unless you’re able to redefine something or something in it in the same way).

    Basically, in this case the only thing you could do is to write (let’s assume something is function () { alert(my.var) })

    var oldalert = window.alert;
    window.alert = function (message) {
        oldalert(message === 'cake' ? 'whatever you want' : message);
    }
    

    Well, you’ve got an idea.

    Injecting some code in between my.var = 'cake'; and my.function(); is, from the other side, imposible. Roughly speaking, you can choose between two options, whether your code will be executed before my.var = 'cake'; or after my.function();. Executing your code aftre my.var = 'cake'; but before my.function(); is impossible (if we’re speaking of a production environment; of course you could do anything by hands using the debugger, if you need to modify my.var for a debugging purpose).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking how to inject my own page into VS2010 Tools->Options window in my
I'm looking for method to inject value into a <c:if test> . The code
I am looking into methods to inject javascript into any webpage loaded in the
i was looking how to inject a dll into a program (exe, or dll,
I am looking into integration testing frameworks for OSGi applications. From here , I've
I'm looking for suggestions on how to inject runtime dependencies into JPA entities retrieved
I'm looking for a way to inject some events into a flash movie running
I'm looking for a way to inject a keystroke into the OS keyboard input
I am looking for a way to inject values from the fragment (#) of
I've been using Seam 2 (also started looking into Java EE 6) in my

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.