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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:53:26+00:00 2026-06-07T05:53:26+00:00

A button on my web page upon clicking performs the following action i.e. Injects

  • 0

A button on my web page upon clicking performs the following action i.e. Injects the script into the page

function InjectToolbar() {
    var script = document.createElement('script');
    scriptFarfalla.src = 'some_Path'
    document.getElementsByTagName('head')[0].appendChild(script);

}

.
.
.
.
.
.

It successfully performs the action desired. But when I reload the page the script is lost

Is there any method/technique with which I can buffer the button’s click
Like a toggle button

Toggle…..> script injected

Toggle…..> script detached

  • 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-07T05:53:27+00:00Added an answer on June 7, 2026 at 5:53 am

    Everything that happens in javascript is reset when you leave a page (and return to it). So you need a way to store whether something is loaded or not. This depends on how long you want this to be “saved”/”remembered”. There are a few options for you to save this information – Cookies, HTML5 localStorage, HTML5 sessionStorage, and any server session usage you have available (if applicable). So if you want to implement something like this, you now need code onload of your page that checks the specific storage to see if you have set it. If so, inject the script. Here’s what I mean:

    window.onload = function () {
        if (checkIfInjected()) {
            scriptInjection(true);
        }
    }
    
    function toggleInjection() {
        if (checkIfInjected()) {
            scriptInjection(false);
        } else {
            scriptInjection(true);
        }
    }
    
    function scriptInjection(inject) {
        if (inject == true) {
            var script = document.createElement('script');
            script.src = 'some_Path';
            script.id = 'injected_script_id';
            document.getElementsByTagName('head')[0].appendChild(script);
    
            // Set the storage to say that script is injected
        } else {
            var the_script = document.getElementById("injected_script_id");
            the_script.parentNode.removeChild(the_script);
            the_script = null;
    
            // Set the storage to say that script has been removed (or remove from storage altogether)
        }
    }
    
    function checkIfInjected() {
        // The following syntax is wrong for anything - you need to use the correct getter for the storage type you use
        return storage.contains("script_injected");
    }
    
    <input type="button" id="button1" onclick="toggleInjection();" />
    

    Now it is up to you to determine what storage type you want because they all do different things, including how things are stored, what they are stored for, and how long they are stored for.

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

Sidebar

Related Questions

I have an ASP.NET web page having a button in it. Clicking the button,
How can you open windows program by pressing a button on web page I
In a web page button click event we need to export 2,00,000 to 5,00,000
I would like the button on my web page to toggle the visibility of
I'm working on a web page that saves in user information on a button
How would you make a button in cocoa when clicked open a web page?
I have a standard ASP.NET 2.0 web page with a Delete button on it.
I want to go to a web page on the click of a button
I have my web applicatoin initialize method run based upon the page that is
I have a web page that contains two articles. Upon loading this page, jQuery

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.