Avatar billede sjsat Nybegynder
02. januar 2000 - 13:27 Der er 2 kommentarer og
1 løsning

Lommeregner

Hvilket java script skal man bruge for man kan "åbne" windows lommeregner, ved at trykke på et link?

på forhånd tak & og godt nytår!
Avatar billede 127144146281 Nybegynder
02. januar 2000 - 13:47 #1
prøv med;

(NT/Win2000)
<a href="file://c:\winnt\system32\calc.exe">&Aring;bn Lommeregner</a>

(Win95/98)
<a href="file://c:\windows\system\calc.exe">&Aring;bn Lommeregner</a>

Avatar billede tigerdyr Nybegynder
02. januar 2000 - 21:15 #2
Eller lav en lommeregner i JS... (Kan mindes noget om et eksempel på det, på www.femalenerd.com)
Avatar billede Slettet bruger
06. januar 2000 - 15:14 #3
hvis du ikke kan finde ud af at åbne windows lommeregner så er her en lang kildekode i javascript til en lomme regner..


<html>

<head>

<title>Lommeregner</title>
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
<base target="indhold">
</head>

<body id="Me">

<h3>Java lommeregner</h3>
<script LANGUAGE="JavaScript" FOR="window" EVENT="onload">
    initCalculator();
</script>
<script LANGUAGE="JavaScript">
public_description = new createCalculator();
var inScriptlet = (typeof(window.external.version) == "string")
var m_memValue        = 0;
var m_stackValue        = 0;
var m_operator        = "";
var m_operatorSetLast    = false;
var m_justCleared    = true;
var m_buttonColor    = "gray";
var m_hiliteColor    = "black";
var m_buttonFont        = "Tahoma";
var m_backColor        = "#090909";
var m_textColor        = "white";
var m_current        = null;
var m_numHistoryElems    = 5;
var m_history        = new Array( 10 );
var m_timeoutID = null;
function createCalculator()
{
    this.get_Value = getCurrentValue;
    this.put_Value = setCurrentValue;
    this.get_BackColor = getBackColor;
    this.put_BackColor = setBackColor;
    this.get_ButtonColor = getButtonColor;
    this.put_ButtonColor = setButtonColor;
    this.get_HiliteColor = getHiliteColor;
    this.put_HiliteColor = setHiliteColor;
    this.get_TextColor = getTextColor;
    this.put_TextColor = setTextColor;
    this.get_ButtonFont = getButtonFont;
    this.put_ButtonFont = setButtonFont;
    this.evaluate = evaluate;
    this.event_OnChange = "";
    this.event_OnEvaluate = "";
}
function initCalculator()
{
    setButtonColor( m_buttonColor );
    setBackColor( m_backColor );
    setButtonFont( m_buttonFont );
    initHistory();
}

///////////////////////////////////////////////////////////////////////////
// OPERATION FUNCTIONS
///////////////////////////////////////////////////////////////////////////

function percent()
{
    //HACK:  Don't call setCurrentValue, or the Change event will fire twice
    currentValue.value = eval( getCurrentValue() ) / 100;
    evaluate();
}

function changeSign()
{
    setCurrentValue( -1 * eval( getCurrentValue() ) );
}

function invert()
{
    setCurrentValue( 1 / eval( getCurrentValue() ) );
}

function squareroot()
{
    setCurrentValue( Math.sqrt( getCurrentValue() ) );
}

function setOperator(newOp)
{
    if( m_operator != 0 )
        evaluate();

    m_operator = newOp;
    m_stackValue = eval( currentValue.value );
    m_operatorSetLast = true;
}

function evaluate()
{
    tempValue = eval( currentValue.value );

    if( m_operator == 1 )
        result = m_stackValue + tempValue;
    else
    if( m_operator == 2 )
        result = m_stackValue - tempValue;
    else
    if( m_operator == 3 )
        result = m_stackValue * tempValue;
    else
    if( m_operator == 4 )
    {
        if( tempValue != 0 )
            result = m_stackValue / tempValue;
        else
            result = "NaN";
    }
    else
        return;
   
    m_operator = 0;
    m_justCleared = true;

    setCurrentValue( result );

    if( inScriptlet )
        window.external.raiseEvent( "event_OnEvaluate", window.document );

    addToHistory( result );
}

///////////////////////////////////////////////////////////////////////////
// MEMORY FUNCTIONS
///////////////////////////////////////////////////////////////////////////

function setMemIndicator( memValue )
{
    if( memValue == 0 )
        MEMINDICATOR.innerText = " "
    else
        MEMINDICATOR.innerText = "M"
}

function memSet(number)
{
    m_memValue = number;
    setMemIndicator( m_memValue );
}

function memRecall()
{
    setCurrentValue( m_memValue );
}

function memPlus(number)
{
    memSet( eval( m_memValue ) + eval( number ) );
}

function clearValue(everything)
{
    setCurrentValue(0);
    m_stackValue = 0;
    setOperator(0);
    if( everything )
    {
        memSet(0);
        initHistory();
    }
    m_justCleared = 0;
}

///////////////////////////////////////////////////////////////////////////
// PROPERTY FUNCTIONS AND UTILITIES
///////////////////////////////////////////////////////////////////////////

function redoButtons()
{
    var col;
    var ct;

    col = document.all.tags("TD");
    for( ct = 0; ct < col.length; ++ct )
        if( isCalculatorButton( col[ct] ) )
        {
            col[ct].style.backgroundColor = m_buttonColor;
            col[ct].style.color = m_textColor;
        }
}

function getCurrentValue()
{
    return currentValue.value;
}

function setCurrentValue( newValue )
{
    currentValue.value = newValue;
    if( inScriptlet )
        window.external.raiseEvent( "event_OnChange", window.document );
}

function getBackColor()
{
    return m_backColor;
}

function setBackColor(newColor)
{
    m_backColor = newColor;
    Me.style.backgroundColor = m_backColor;
}

function getButtonColor()
{
    return m_buttonColor;
}

function setButtonColor(newColor)
{
    m_buttonColor = newColor;
    redoButtons();
}

function getHiliteColor()
{
    return m_hiliteColor;
}

function setHiliteColor(newColor)
{
    m_hiliteColor = newColor;
}

function getTextColor()
{
    return m_textColor;
}

function setTextColor(newColor)
{
    m_textColor = newColor;
    redoButtons();
}

function getButtonFont()
{
    return m_buttonFont;
}

function setButtonFont(newFont)
{
    m_buttonFont = newFont;
    Me.style.fontFamily = m_buttonFont;
}

function postNumber(number)
{
    if( !m_operatorSetLast && !m_justCleared )
        currentValue.value = currentValue.value + number;
    else
        currentValue.value = number;

    m_operatorSetLast = false;
    m_justCleared = false;

    if( inScriptlet )
        window.external.raiseEvent( "event_OnChange", window.document );
}

function postDot()
{
    if( isNaN( currentValue.value + "." ) )
        return;

    postNumber(".");
}

///////////////////////////////////////////////////////////////////////////
// HISTORY FUNCTIONS
///////////////////////////////////////////////////////////////////////////

function initHistory()
{
    var ct;

    for( ct = m_history.length - 1; ct >= 0; --ct )
    {
        if( ct % 2 == 0 )
            m_history[ ct ] = "";
        else
            m_history[ ct ] = "historyPick" + ( (ct+1) / 2 );
    }

    if( inScriptlet )
        window.external.setContextMenu( m_history );
}

function historyPick1()
{
    setCurrentValue( m_history[ 2 * 0 ] );
}

function historyPick2()
{
    setCurrentValue( m_history[ 2 * 1 ] );
}

function historyPick3()
{
    setCurrentValue( m_history[ 2 * 2 ] );
}

function historyPick4()
{
    setCurrentValue( m_history[ 2 * 3 ] );
}

function historyPick5()
{
    setCurrentValue( m_history[ 2 * 4 ] );
}

function addToHistory( result )
{
    var ct;

    // Bubble down the previous history elements
    for( ct = m_history.length - 1; ct >= 2; --ct )
    {
        if( ct % 2 == 0 )
            m_history[ ct ] = m_history[ ct-2 ];
        else
            m_history[ ct ] = "historyPick" + ( (ct+1) / 2 );
    }
   
    // Add the new one
    m_history[ 0 ] = result;
    m_history[ 1 ] = "historyPick1";

    if( inScriptlet )
        // Looks like we need to re-set the context menu
        window.external.setContextMenu( m_history );
}

///////////////////////////////////////////////////////////////////////////
// UTILITY FUNCTIONS
///////////////////////////////////////////////////////////////////////////

function isCalculatorButton( item )
{
    return ( item.id.substring(0, 3) == "Btn" );
}

function isOperator( val )
{
    if( val == "/" || val == "*" || val == "+" || val == "-" )
        return true;
    return false;
}

function handleOperator( op )
{
    if( op == "*" )
        setOperator( 3 );
    else
    if( op == "/" )
        setOperator( 4 );
    else
    if( op == "+" )
        setOperator( 1 );
    else
    if( op == "-" )
        setOperator( 2 );
}

///////////////////////////////////////////////////////////////////////////
// EVENT HANDLERS
///////////////////////////////////////////////////////////////////////////

function doInput( inText )
{
    if( !isNaN( inText ) )
        postNumber( inText );
    else
    if( inText == "CE" )
        clearValue( true );
    else
    if( inText == "C" )
        clearValue( false );
    else
    if( inText == "MC" )
        memSet( 0 );
    else
    if( inText == "sqrt" )
        squareroot();
    else
    if( inText == "MR" )
        memRecall();
    else
    if( inText == "MS" )
        memSet( getCurrentValue() );
    else
    if( inText == "1/x" )
        invert();
    else
    if( inText == "." )
        postDot();
    else
    if( inText == "=" )
        evaluate();
    else
    if( inText == "M+" )
        memPlus( getCurrentValue() );
    else
    if( inText == "%" )
        percent();
    else
    if( inText == "+/-" )
        changeSign();
    else
    if( isOperator( inText ) )
        handleOperator( inText );
}

function handleClick()
{
    var current = window.event.srcElement;

    // Return if not on an element
    if( current == null )
        return;

    // Return if not a "button"
    if( !isCalculatorButton( current ) )
        return;

    // Draw "depressed"
    current.style.backgroundColor = m_hiliteColor;
    current.style.color = m_textColor;

    // Do the right thing
    doInput( current.innerText );

    // Clean up
    m_current = current;

    // change the button's color back to not-depressed in 75 milliseconds
    m_timeoutID = setTimeout( "resetButtonColor( m_current, m_textColor, m_buttonColor );", 75 );
   
}

function resetButtonColor( item, newColor, newBackColor )
{
    item.style.color = newColor;
    item.style.backgroundColor = newBackColor;
    clearTimeout( m_timeoutID );
}

function handleMouseOver()
{
    var hotButton = window.event.srcElement;

        if( isCalculatorButton( hotButton ) )
    {
        hotButton.style.color = m_hiliteColor;
    }
}

function handleMouseOut()
{
    var hotButton = window.event.srcElement;

        if( isCalculatorButton( hotButton ) )
    {
        hotButton.style.color = m_textColor;
    }
}

function filterKeys()
{
    var keycode = window.event.keyCode;

    // Force the focus to be inside the textbox for keystrokes to work.  This solves a couple of problems.
    currentValue.focus();

    if( keycode == 46 )
    {
        // Only allow a "." if there isn't already one
        if( getCurrentValue().indexOf( "." ) != -1 )
            window.event.returnValue = false;
    }
    else
    if( keycode == 43 )
        doInput( "+" );
    else
    if( keycode == 45 )
        doInput( "-" );
    else
    if( keycode == 42 )
        doInput( "*" );
    else
    if( keycode == 47 )
        doInput( "/" );
    else
    if( keycode == 61 )
        doInput( "=" );

    if( ( keycode >= 48 && keycode <= 57 ) || keycode == 46 )
    {
        if( m_operatorSetLast || m_justCleared )
            currentValue.value = "";

        m_operatorSetLast = false;
        m_justCleared = false;
    }
    else
        window.event.returnValue = false;

    // Slight inconsistency here -- we're firing the event BEFORE the value has actually changed.
    // But it's changing immediately thereafter.  Hmmm...
    if( inScriptlet && window.event.returnValue )
        window.external.raiseEvent( "event_OnChange", window.document );
}

</script>


<table CELLSPACING="1" CELLPADDING="1" BORDER="0" WIDTH="100" onclick="handleClick()" onmouseover="handleMouseOver()" onmouseout="handleMouseOut()" onkeypress="filterKeys()">
  <tr>
    <td ID="TxtValue" ALIGN="CENTER" VALIGN="CENTER" COLSPAN="6" HEIGHT="13%"><input NAME="currentValue" VALUE="0" size="20"></td>
  </tr>
  <tr>
    <td WIDTH="59%" ID="LblM" ALIGN="CENTER" COLSPAN="4" HEIGHT="19%"><b><span ID="MEMINDICATOR"></span></b></td>
    <td WIDTH="20%" ID="BtnCE" ALIGN="CENTER" HEIGHT="19%">CE</td>
    <td WIDTH="20%" ID="BtnC" ALIGN="CENTER" HEIGHT="19%">C</td>
  </tr>
  <tr>
    <td WIDTH="20%" ID="BtnMC" ALIGN="CENTER" HEIGHT="17%">MC</td>
    <td WIDTH="16%" ID="Btn7" ALIGN="CENTER" HEIGHT="17%">7</td>
    <td WIDTH="16%" ID="Btn8" ALIGN="CENTER" HEIGHT="17%">8</td>
    <td WIDTH="16%" ID="Btn9" ALIGN="CENTER" HEIGHT="17%">9</td>
    <td WIDTH="16%" ID="BtnDiv" ALIGN="CENTER" HEIGHT="17%">/</td>
    <td WIDTH="16%" ID="BtnSqrt" ALIGN="CENTER" HEIGHT="17%">sqrt</td>
  </tr>
  <tr>
    <td WIDTH="20%" ID="BtnMR" ALIGN="CENTER" HEIGHT="17%">MR</td>
    <td WIDTH="16%" ID="Btn4" ALIGN="CENTER" HEIGHT="17%">4</td>
    <td WIDTH="16%" ID="Btn5" ALIGN="CENTER" HEIGHT="17%">5</td>
    <td WIDTH="16%" ID="Btn6" ALIGN="CENTER" HEIGHT="17%">6</td>
    <td WIDTH="16%" ID="BtnMult" ALIGN="CENTER" HEIGHT="17%">*</td>
    <td WIDTH="16%" ID="BtnPercent" ALIGN="CENTER" HEIGHT="17%">%</td>
  </tr>
  <tr>
    <td WIDTH="20%" ID="BtnMS" ALIGN="CENTER" HEIGHT="17%">MS</td>
    <td WIDTH="16%" ID="Btn1" ALIGN="CENTER" HEIGHT="17%">1</td>
    <td WIDTH="16%" ID="Btn2" ALIGN="CENTER" HEIGHT="17%">2</td>
    <td WIDTH="16%" ID="Btn3" ALIGN="CENTER" HEIGHT="17%">3</td>
    <td WIDTH="16%" ID="BtnSubtract" ALIGN="CENTER" HEIGHT="17%">-</td>
    <td WIDTH="16%" ID="BtnInvert" ALIGN="CENTER" HEIGHT="17%">1/x</td>
  </tr>
  <tr>
    <td WIDTH="20%" ID="BtnMPlus" ALIGN="CENTER" HEIGHT="17%">M+</td>
    <td WIDTH="16%" ID="Btn0" ALIGN="CENTER" HEIGHT="17%">0</td>
    <td WIDTH="16%" ID="BtnChangeSign" ALIGN="CENTER" HEIGHT="17%">+/-</td>
    <td WIDTH="16%" ID="BtnDot" ALIGN="CENTER" HEIGHT="17%">.</td>
    <td WIDTH="16%" ID="BtnAdd" ALIGN="CENTER" HEIGHT="17%">+</td>
    <td WIDTH="16%" ID="BtnEquals" ALIGN="CENTER" HEIGHT="17%">=</td>
  </tr>
</table>
<font color=yellow size=3 face=impact></font>


</body>
</html>
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester