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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:30:46+00:00 2026-05-25T19:30:46+00:00

I am making a javascript greasemonkey script that redirects you when it finds a

  • 0

I am making a javascript greasemonkey script that redirects you when it finds a certain string in a webpage. Here is my code:

// ==UserScript==<br>
// @name No 009 Sound System!<br>
// @version 1.0<br>
// @namespace http://www.cakeman.biz/<br>
// @description Warn user when about to view a youtube video with 009 Sound System audio<br>
// @include http://*/*<br>
// @copyright  2011+, Zack Marotta 
// ==/UserScript==

var result, search_term = 'somerandomsearchterm';
var str = document.URL;
var url_check = str.search(search_term);
if (url_check !== -1) {
var result = search_term;
alert(str);
    window.location = "http://www.web.site";
}

Nothing happens when the script runs. What did I do wrong?

  • 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-25T19:30:46+00:00Added an answer on May 25, 2026 at 7:30 pm

    For some specific functions, you have to use unsafeWindow instead of window in a Greasemonkey UserScript. If you want to get your script work at GreaseMonkey and other locations, use this:

    var win = typeof unsafeWindow != "undefined" ? unsafeWindow : window;
    

    I’ve shrinkened by original answer, because that seems not to be your issue. Most likely, you’ve forgot to add // @include to your meta block.

    If your script has to redirect a certain, fixed page using GreaseMonkey, you can also shorten your scrip to:

    // ==UserScript==
    // @name Redirect
    // @include *i-am-afraid-of-this-word*
    // ==/UserScript==
    
    location.href = "http://www.google.com/search?q=need-help-getting-courage";
    

    For more information about the meta block, see: http://wiki.greasespot.net/Metadata_block

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

Sidebar

Related Questions

I am making a 2D game in javascript/ajax, that will be using data stored
I am making a greasemonkey script and i would like a link to go
Hey guys, I'm making a javascript rock, paper, scissors game! So the code is
I'm playing with the idea of making a completely JavaScript-based zip/unzip utility that anyone
I am making a javascript code editor online, and right now I'm doing the
I'm making a simple javascript app that needs to run locally (on a CD
I am making a javascript bookmarklet that resizes all images, periodically. javascript: function x(){
There is a webpage i am making a greasmonkey script for. This page has
I'm making a javascript/canvas game and I saw this example on CSS Tricks. Here's
I have some JavaScript that is making an Ajax call to a relative url

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.