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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:55:47+00:00 2026-06-14T20:55:47+00:00

I have a GM script which inserts a link on to the page, and

  • 0

I have a GM script which inserts a link on to the page, and then adds an event listener for when its clicked.

This then runs a function which contains among other things some jQuery.get calls. These calls however do not seem to fire unless I use the unsafeWindow version of jQuery.

function runMyFunc() {
    console.log('myFunc is called');

    $.get('index.php',function () {
        console.log('jQuery.get worked');
    });
}

$("#someHook").before('<a id="myLink">Link</a>');

$('#myLink').click(runMyFunc);

The above will output ‘myFunc is called’ to console, but will not do anything with the .get

I’m using FF17 and GM1.5, jQUery from http://code.jquery.com/jquery.js

Is there a nicer way of getting this to work than using unsafeWindow? I had this working before GM 1.0 and have a lot of $.get which I would need to change in my scripts, not all of which are run from the same scenario

  • 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-14T20:55:48+00:00Added an answer on June 14, 2026 at 8:55 pm

    Your code works fine for me. Why/How do you think $.get is not working?

    Remember that you will never see the 'jQuery.get worked' message if there is a server error (404 etc.) with index.php. Did you check the Firebug Net panel, or Wireshark, etc. to see if the AJAX call was made?

    Anyway, you can see that code working, plus some error handling if you install this Greasemonkey script:

    // ==UserScript==
    // @name     _delme9h762
    // @include  http://YOUR_SERVER.COM/YOUR_PATH/*
    // @include  http://fiddle.jshell.net/ZqhRH/*
    // @require  http://code.jquery.com/jquery.js
    // @grant    GM_addStyle
    // ==/UserScript==
    /*- The @grant directive is needed to work around a design change
        introduced in GM 1.0.   It restores the sandbox.
    */
    
    function runMyFunc() {
        console.log('myFunc is called');
    
        $.get('index.php', function () {
            console.log ('jQuery.get worked');
        } )
        .error ( function (respObj) {
            console.log ("Error! ", respObj.status, respObj.statusText);
        } )
        .complete ( function (respObj) {
            console.log ("AJAX Complete. Status: ", respObj.status);
        } )
        ;
    }
    
    $("#someHook").before('<a id="myLink">Link</a>');
    
    $('#myLink').click(runMyFunc);
    

    And then visit fiddle.jshell.net/ZqhRH/1/show/.

    Note, the console will show:

    myFunc is called
    Error! 404 NOT FOUND
    AJAX Complete. Status: 404

    On the jsFiddle site, because index.php does not exist there, but $.get() is otherwise working perfectly.

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

Sidebar

Related Questions

If I have a script which inserts data then exits, the script will be
I have a form in html which runs a php script whitch inserts text
I have a script which similar to this: foo.php class Foo { function Foo()
I have a php function which inserts a searchbar into each page on a
I have the following PHP script which runs nicely and inserts all the data
I have a script which validates each stage of a form and adds a
I have this script which basically toggles a bgColor class on and off so
I have a script which hides (display:none) certain divs in the list on page
I have a Jquery Script which is depenedent on this Script Sort.js . Can
I have a Greasemonkey script which operates on a search results page at a

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.