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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:11:13+00:00 2026-06-11T17:11:13+00:00

Let me start off by saying that the code in question is part of

  • 0

Let me start off by saying that the code in question is part of a UserScript and, as such, normal DOM rules and Javascript methods do not work.

Here is the situation:

I have written a UserScript that interacts with an online chat site. I have a number of button that are generated within the user script. Some of these buttons are located inside of a form, while many of them are not.

Elements added through GreaseMonkey live in two worlds — they live on the page DOM and they live in the slightly elevated world of UserScripts, which mean that these lines:

event.preventDefault = true;
event.stopPropagation = true;

prevent the rest of the UserScript actions from running, but it does not stop the button from causing a form submit.

As a work around, I am building span elements instead of a button. This works, but it really breaks the visual layout of the chat room.

Does anyone know a way to prevent elements added by UserScripts to prevent form submissions? Failing that, I’ll dream that someone knows how to make a span look like a native button.

Edit: I have a solution which seems to be working — but I haven’t fully tested it under every UserScript environment:

  // Yes, yes, poorly named but it was a SPAN
  // userWindow is an alias for unsafeWindow.
  // (Used to run under a userScript environment for IE and I had to emulate a lot)
  var span = document.createElement("input");
  span.value = text;
  span.type = "button";
  span.className = "cpbutton";

  // Add it to the body just long enough to set up a page-level, DOM0 event handler
  var body = userWindow.document.getElementsByTagName("body")[0];
  var tname = "IAmTheVeryModelOfAModernMajorGeneral";     
  span.id = tname;
  body.appendChild(span);
  userWindow.document.getElementById(tname).onclick = function() {return false;};
  body.removeChild(span);
  span.id = "";
  • 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-11T17:11:14+00:00Added an answer on June 11, 2026 at 5:11 pm

    See the W3C spec for <button>.
    By default, a <button> element acts as a submit button inside a form. This means that event.preventDefault() (the correct usage, BTW), on the click handler, may not be enough to stop the form submit.

    In that case you could intercept the form’s submit event too BUT, the smart thing to do is to use the type attribute to tell the browser not to treat the button as a submit button.
    EG:

    <button type="button">Your button markup</button>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off, let me start by saying that I am totally new to working
Preface Let me start off by saying that I'm a relatively new programmer and
Let me start off by saying that I am very new to WPF and
Let me start off by saying that I am completely new with WPF (this
Ok, let me first start off by saying that I've only ever dealt with
Let me start off by saying that I am not an expert in C.
Let me start off by saying that this is my first real Cocoa app.
First off, let me start by saying, I know this exact question has been
Let me start this off by saying that I'm an intern with no Powershell
Let me start off by saying my JavaScript skills are lacking, to say the

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.