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

  • Home
  • SEARCH
  • 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 947529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:05:45+00:00 2026-05-15T23:05:45+00:00

I’m injecting Javascript into a page w/ Greasemonkey, doing some processing on the body

  • 0

I’m injecting Javascript into a page w/ Greasemonkey, doing some processing on the body content (adding markup) then re-inserting the content. The problem is that all the events in the original content are lost, breaking things like onClick events that were added when the page initially loaded.

My original idea was to do this (using jQuery) to just re-add the script tags to the head:

$('script').each(function(s, script) {  $(script).appendTo('head');  })

or just:

$('script').appendTo('head');

I thought this would cause scripts to reload/reeval, but it doesn’t work.

A simple example of where I’d like to do this would be on: http://en.m.wikipedia.org/wiki/John_Hardy_%28song%29 I’d need to re-apply the this event found in application.js

 $("h2.section_heading").click(function() {
 // Do something
 }) 
  • 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-15T23:05:45+00:00Added an answer on May 15, 2026 at 11:05 pm

    The question of whether and when browsers execute <script> tags that are being added to the page by various methods is a thorny one, made if anything more complicated by jQuery’s attempts to work around the issue. You really don’t want to get into this.

    In any case, as Pointy says, there is no guarantee whatsoever that simply running the page’s scripts a second time will make them work with the new content. They may have all sorts of references to old (now replaced) nodes and may not expect to be entered a second time at all.

    Don’t do processing on markup. HTML string hacking is massively unreliable quite apart from the problem of it replacing all the old objects when you write it back with innerHTML. If you’re, say, adding '<span class="highlight">' to the HTML via regex hacks, you’ve just dug yourself a well of bugs, incompatibilities and potential XSS vulnerabilities.

    You’ve got a perfectly good DOM tree sitting in the browser. Do the processing on that, adding elements and setting attributes over the existing nodes! It’s easier, way more reliable, and for many operations much faster.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into

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.