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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:06:26+00:00 2026-06-09T10:06:26+00:00

I am using javax.script in Java, and I’d like to be able to detect

  • 0

I am using javax.script in Java, and I’d like to be able to detect whether the current Javascript implementation is Rhino. I’m doing this because I need to script to work properly on web pages as well as in Rhino.

Javascript pseudocode:

function writeMessage(message) {
    if (implementation is Rhino) {
        print(message);
    }
    else if (script is running in a web browser) {
        document.write(message);
    }
}
  • 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-09T10:06:29+00:00Added an answer on June 9, 2026 at 10:06 am

    Ah, there we’ve got it in your comment. Just use the feature detection:

    var writeMessage = document && document.write
      ? document.write.bind(document)
      : print;
    

    And then use writeMessage(string) all over your script. This is a short form of

    if (document && document.write)
        var writeMessage = function(message) { document.write(message); };
    else
        var writeMessage = function(message) { print(message); };
    

    which is better than what you suggested in the question, where the detection would be applied every time the function is invoked:

    function writeMessage(message) {
        if (document && document.write) { // running in a web browser
            document.write(message);
        } else { // it will be Rhino
            print(message);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using this java script library to show ratings http://www.fyneworks.com/jquery/star-rating/#tab-Overview . I'm using below
Using the scripting framework (javax.script.*), it's really easy to get basic integration between Java
It's my first time using Java Script.... What does this do? var INTEGER_SINGLE =
i want to create vertical expandable list view using java script.like here click .If
I'm currently using the javax.script package for interpreting and executing Javascript code on the
I want to create application to fetch the current location data using Java script.
I'm using the javax.script.* package of the JDK. Specifically, I'm using the JavaScript engine,
All I am using my SOAP API using java script. this example explain how
I want to select current(cursor position) element in CKEditor using java script. When right
Possible Duplicate: how to count the site current visitors using java script or 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.