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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:05:26+00:00 2026-05-26T09:05:26+00:00

I have this bookmarklet, which follows what was proposed in this topic : javascript:

  • 0

I have this bookmarklet, which follows what was proposed in this topic:

javascript: (function () {  
    var jsCode = document.createElement('script');  
    jsCode.setAttribute('src', 'http://path/to/external/file.js');  
  document.body.appendChild(jsCode);  
 }());

My question is, how can I give the server script some parameter (e.g. page title)?
Server script is the following (just some PoC so far):

(function(message){
    alert(message + " " + Math.random()*100);
})();
  • 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-26T09:05:26+00:00Added an answer on May 26, 2026 at 9:05 am

    To pass a parameter to a server-side script, extend the query string:

        jsCode.setAttribute('src', 'http://path/to/external/file.js?parameter=' + document.title);
    

    If you’re intending to pass a parameter to the returned script, add an onload handler to the script element:

    javascript:(function() {
        var jsCode = document.createElement('script');  
        var parameter = document.title; //Define parameter
        jsCode.onload = function() {
            // If the function exists, use:
            if(typeof special_func == "function") special_func(parameter);
        };
        jsCode.setAttribute('src', 'http://path/to/external/file.js');
        document.body.appendChild(jsCode);
    })();
    

    Response script (file.js):

    function special_func(param){
        alert(param);
    }
    

    Update / example

    If you want to pass (multiple) variable(s) to your response script, use the following code:

    javascript:(function() {
        var jsCode = document.createElement('script');  
        var params = ["test", document.title]; //Define parameter(s)
        var thisObject = {}; // `this` inside the callback function will point to
                             // the object as defined here.
        jsCode.onload = function() {
            // If the function exists, call it:
            if (typeof special_func == "function") {
                special_func.apply(thisObject, params);
            }
        };
        jsCode.setAttribute('src', 'http://path/to/external/file.js');
        document.body.appendChild(jsCode);
    })();
    

    http://path/to/external/file.js:

    // Declare / Define special_func
    var special_func = (function(){
        var local_variable = "password";
        var another_local_title = "Expected title";
    
        //Return a function, which will be stored in the `special_func` variable
        return function(string, title){ //Public function
            if (title == another_local_title) return local_variable;
        }
    })();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this lovely javascript bookmarklet... javascript:var nam=blablabla&name; var els=document.getElementsByName(nam); if(els.length == 0) alert(nam);
I have this script loaded on a page: (function() { window.alert('bookmarklet started'); function AjaxSuccess(data,
I have this bookmarklet javascript:%28function%28%29%7Bvar%20a%3Ddocument.createElement%28%22script%22%29%3Ba.type%3D%22text%2Fjavascript%22%3Ba.src%3D%22http://www.foo.com/bar.js.php%3F%22%2BMath.random%28%29%3Bdocument.getElementsByTagName%28%22head%22%29%5B0%5D.appendChild%28a%29%7D%29%28%29%3B On my home page I will create a button
I have this bookmarklet: javascript:void(window.open(document.links[Math.floor(Math.random()*document.links.length)].href,'_blank')) It outputs random link from a document full of
I have this bookmarklet, i.e. it does not start with 'http:' but with 'javascript:'.
I have the following javascript bookmarklet which opens a new popup window with a
I have come across Evernote's bookmarklet and was wondering how this worked. You can
I have this line in a javascript block in a page: res = foo('<%=
I have this string 'john smith~123 Street~Apt 4~New York~NY~12345' Using JavaScript, what is the
I have this RewriteRule that works too well :-) RewriteRule ^([^/]*)/$ /script.html?id=$1 [L] 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.