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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:14:06+00:00 2026-05-26T17:14:06+00:00

I’m trying to create a Javascript bookmarklet, which would extract a numeric ID from

  • 0

I’m trying to create a Javascript bookmarklet, which would extract a numeric ID from an URL:

   http://site-1/script-1.php?ID=12345678&other-params

and then redirect the browser to a new URL:

   http://site-2/script-2.php?id=12345678

I’ve searched net for bookmarklet examples and I have 2 questions please:

1) Do I need to place my JS-code inside a void?

javascript:void(XXX);

What does void mean in this context?

2) Should I use location.href for reading the old URL and assigning a new constructed URL? I’m asking because I’ve seen many strange pieces of code, like String(location.href) etc. – like it needs some casting to String (does it?)

UPDATE: I’ve tried the following code, but nothing happens in Chrome unfortunately, when I’m on the old page and click my bookmarklet (hoping to navigate to the new page):

javascript:void (
    if ( var match = location.search.match(/id=(\d+)/i) ) 
        location = 'http://site-2/script-2.php?id=' + match[1];
)

(I’ve added line-breaks above and yes I’m trying to use a single “=”)

UPDATE 2: My 2nd try – just trying to display a new URL:

javascript:void (
    var match = location.search.match(/ID=(\d+)/);
    alert('http://site-2/script-2.php?id=' + match[1]);
)

but still nothing happens, when I click the bookmark at the bookmarks bar. And I see in Google Chrome console:

Uncaught SyntaxError: Unexpected token var
  • 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-26T17:14:07+00:00Added an answer on May 26, 2026 at 5:14 pm

    1) If your bookmarklet returns a value so that after all code is run, the url could be read as: javascript:%somestring% the browser will display that string in the browser window. So void() is just a safeguard (ref ...The void operator evaluates the given expression and then returns undefined...) against accidently overwriding the document. This means, if you’re careful you don’t need void.

    2) No need to cast it, as it will happen automatically if you don’t provide a string value.


    My bookmarklet template:

    <a href="javascript:(function(){
      // do stuff but do not return anything
    }());">something</a>
    

    Update:

    javascript:(function () {
      var match = window.location.href.match(/ID=(\d+)/);
      if (match.length > 0) {
        alert('http://site-2/script-2.php?id=' + match[1]);
        // or after debugging: window.location = 'http://site-2/script-2.php?id=' + match[1];
      }
    }());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,

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.