Page 1 of 1

How to get text from javascript alert box

Posted: 25 Feb 2020, 20:04
by JanMolendijk
Good evening (dutch-time) I have a javascript what can copy text to a clip-board + it has a button to show the item-list in a alert-box.

But can`t find out how I can select the text from the alertbox.

Hope you can help me out.... ?

Code: Select all

<body>
<table WIDTH="100%" BORDER="0" CELLSPACING="5" CELLPADDING="5">
  <td align="center">
  <table width="100%">
  <tr>
    <td WIDTH="100%" align="center"><form name="history">
 
      <p><font
    face="ARIEL,HELVETICA" SIZE="-1"><input name="command" type="text" value size="20"> <input type="button"
      value="Add to List"  onclick="f_store(document.history.command.value)"> <input
      name="history" type="button" value="Show List"    onclick="f_print()"> </font> </p>
    </form>
    <p align="center"><font
    face="ARIEL,HELVETICA" SIZE="-1"><script language="JavaScript"> 
<!-- hide it ...
function MakeArray( n ) {
if( n <= 0 ) {
this.length = 0;
return this;
}
this.length = n;
for( var i = 1; i <= n; i++ ) {
this[ i ] = 0;
}
return this;
}
var history = new MakeArray( 15 );
var index = 0;
var cmmnd = 1;
function f_store( sTR ) {
var i;
if( index >= history.length ) {
for( i = 1; i < history.length; i++ )
history[i-1] = history[i];
index = history.length - 1;
}
history[ index ] = cmmnd + ":" + sTR;
++cmmnd;
++index;
document.history.command.value="";
}
function f_print() {
var allCmmnds, i;
allCmmnds = "";
for( i = 0; i < index; i++ )
allCmmnds += history[i] + "\n";
alert( allCmmnds );
}

</script> 

How to get text from javascript alert box

Posted: 26 Feb 2020, 07:00
by Admin
Hello,
You cannot get /copy the text directly from the alert box, but you can get the text (value) from the variable that is added in the alert() function.
So, identify in the javascript code where the text come from, the variable that store the text, and you can get the text from that variable.
In your code, the text is stored in the "history" variable, which is an array. You can get the text you want from that array.
Try study the f_print() function in your code, which contain the alert() instruction.

How to get text from javascript alert box

Posted: 11 Mar 2020, 06:20
by JanMolendijk
Thanks for the support I tried already things with history + f_print
also studied those a little before I asked coursesweb but I shall
when my head is cleared do those staps again.

(vv sorry for my late response incase)