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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:50:46+00:00 2026-05-24T00:50:46+00:00

I’m trying to get a simple bookmarklet working with Rails that creates a form

  • 0

I’m trying to get a simple bookmarklet working with Rails that creates a form with the current page title and URL and submits to create an object.

The problem I’m running into is that when the form submits, it forwards to a “success” page rather than just staying on the same page as it should.

I know the bookmarklet code should return undefined to stop this from happening, but I’ve tried putting void(0) everywhere I can think of but it still forwards on to the next page.

Here are two ways I’ve tried:

javascript:void((function(){
var s = document.createElement('script');
s.setAttribute('language','javascript');
s.setAttribute('src','http://localhost:3000/script/bookmarklet.js');
document.body.appendChild(s);
})());

and:

javascript:(function(){
var s = document.createElement('script');
s.setAttribute('language','javascript');
s.setAttribute('src','http://localhost:3000/script/bookmarklet.js');
document.body.appendChild(s);
void(0);
})();

Could the other .js file be causing the problem? Here it is:

(function() {

function create_form() {
    var path = "http://localhost:3000/links";

    var newform = document.createElement('form');
    newform.setAttribute("method", "post");
    newform.setAttribute("action", path);
    newform.setAttribute("accept-charset","UTF-8");

    var title_hidden_field = document.createElement("input");
    title_hidden_field.setAttribute("type","hidden");
    title_hidden_field.setAttribute("name", "link[title]");
    title_hidden_field.setAttribute("value", "Test Title");

    newform.appendChild(title_hidden_field);

    var url_hidden_field = document.createElement("input");
    url_hidden_field.setAttribute("type","hidden");
    url_hidden_field.setAttribute("name", "link[url]");
    url_hidden_field.setAttribute("value", "http://www.example.com");

    newform.appendChild(url_hidden_field);

    document.body.appendChild(newform);
    newform.submit();
};

create_form();
})();

I tried returning undefined there as well, but the forwarding behavior didn’t change. Could it have something to do with the way rails handles the form post request?

  • 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-24T00:50:47+00:00Added an answer on May 24, 2026 at 12:50 am

    Firstly, void(0) is used to get the return value as undefined which is one way to stop going to next page, but does not apply here. And also, make sure you keep void(0) at the end of the bookmarklet.

    The one way I can think to stop going on to the next page is to first create an invisible inline-frame(iframe)

    var myiframe = document.createElement('iframe');
    myiframe.scrolling = "no";
    myiframe.name = "myiframe";
    myiframe.id = "myiframe";
    myiframe.src = "blank.html"; //so your users wont have to use their bandwith much, I think you can also set it to the about page in many browsers
    myiframe.width = "0px"; //so it becomes invisible
    myiframe.height = "0px"; //""
    document.body.appendChild(myiframe)
    

    or

    var ThisBody = document.body.innerHTML
    ThisBody += '<iframe frameborder="0" scrolling="no" name="myiframe" id="myiframe" src="blank.html" width="0px" height="0px"></iframe>
    

    Then by setting your newform with the target, which is the biggy part here:

    newform.target = "document.getElementById('myiframe')" //our iframe
    

    I think that’s it.

    Also:

    javascript:(function(){
    var s = document.createElement('script');
    s.setAttribute('language','javascript');
    s.setAttribute('src','http://localhost:3000/script/bookmarklet.js');
    document.body.appendChild(s);
    })();void(0)
    

    That’s where void should go ^^

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

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
i want to parse a xhtml file and display in UITableView. what is the
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim

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.