<html>
<head>
<title>Window Object Methods - RJM Programming - June, 2022 ... thanks to https://www.w3schools.com/jsref/obj_window.asp</title>
<script type='text/javascript'>
var soh='';
var template="const prompt = (one,two) => { lasto=window.prompt(one,two); };";
var newt='';
var one='', two='', three='', four='';
var lasto=null;
var myh4ih='';
function setitup(tv, newnewt) {
var thisih='';
var suff=';';
var nts=[];
var varsare=[], ivars;
var curobj=lasto;
var repone='youwillneverfindthiswindow.';
var reptwo='lasto.'
var repthree='youwillneverfindthiswindow.';
var repfour='lasto.'
if (tv.indexOf('(') != -1 && tv.indexOf('()') == -1) {
if (newnewt != '') {
newt=newnewt;
document.getElementById('myh4').style.backgroundColor='orange';
} else {
document.getElementById('optionfunction').innerHTML='function(){ console.log( (new Date() ) ); }';
document.getElementById('myh4').style.backgroundColor='yellow';
tv=tv.replace(/\)\)/g,')').replace('Eval(','').replace('eval(','').replace('EVal(','').replace('one),','one,');
newt=template.replace(/prompt/g, tv.split('(')[0]).replace(/one\,two/g, tv.split('(')[1].split(')')[0]);
// newt=const close = ( ) => { lasto=window.close( ); }; and tv=close( )
// alert('newt=' + newt + ' and tv=' + tv + ' and vars.length=' + tv.split('(')[1].split(')')[0].split(',').length);
}
vars=tv.split('(')[1].split(')')[0].split(',');
for (ivars=0; ivars<vars.length; ivars++) {
if (document.URL.indexOf('popup=') != -1) {
thisih+=' ' + vars[ivars] + '=window.prompt(' + "'Please enter value for " + vars[ivars] + "',''); ";
} else {
if (ivars == 0 && document.getElementById('myselect').value.indexOf('al(one)') != -1) {
var optsare=document.getElementsByTagName('option'), iopts=0;
document.getElementById('optionlasto').style.display='block';
document.getElementById('optionfunction').style.display='block';
document.getElementById('optionwindow').style.display='block';
for (iopts=0; iopts<optsare.length; iopts++) {
if (('' + optsare[iopts].id).indexOf('firstopt') == 0) {
document.getElementById(optsare[iopts].id).style.display='block';
}
}
document.getElementById('select' + vars[ivars]).style.display='block';
if (document.getElementById('myselect').value.indexOf('Eval(') != -1) {
one=eval(lasto);
thisih+=' one=eval(document.getElementById(' + "'select" + vars[ivars] + "'" + ').value); document.getElementById(' + "'select" + vars[ivars] + "'" + ').value=' + "'lasto'" + '; document.getElementById(' + "'select" + vars[ivars] + "'" + ').style.display=' + "'block'" + '; ';
document.getElementById('select' + vars[ivars]).value='lasto';
seloc(document.getElementById('select' + vars[ivars]));
} else if (document.getElementById('myselect').value.indexOf('EVal(') != -1) {
for (iopts=0; iopts<optsare.length; iopts++) {
if (('' + optsare[iopts].id).indexOf('firstopt') == 0) {
document.getElementById(optsare[iopts].id).style.display='none';
}
}
document.getElementById('optionfunction').style.display='none';
document.getElementById('optionwindow').style.display='none';
one=eval(function(){ console.log( (new Date() ) ); });
//thisih+=' one=eval(document.getElementById(' + "'select" + vars[ivars] + "'" + ').value); document.getElementById(' + "'select" + vars[ivars] + "'" + ').value=' + "'function(){ console.log( (new Date() ) ); }'" + '; document.getElementById(' + "'select" + vars[ivars] + "'" + ').style.display=' + "'block'" + '; ';
thisih+=' document.getElementById(' + "'select" + vars[ivars] + "'" + ').value=' + "'function(){ console.log( (new Date() ) ); }'" + '; document.getElementById(' + "'select" + vars[ivars] + "'" + ').style.display=' + "'block'" + '; ';
document.getElementById('select' + vars[ivars]).value='function(){ console.log( (new Date() ) ); }';
seloc(document.getElementById('select' + vars[ivars]));
} else {
document.getElementById('optionlasto').style.display='none';
document.getElementById('optionfunction').style.display='none';
document.getElementById('optionwindow').style.display='none';
if (newnewt == '') {
one=eval(document.getElementById('mybody'));
}
//thisih+=' one=eval(document.getElementById(' + "'select" + vars[ivars] + "'" + ').value); document.getElementById(' + "'select" + vars[ivars] + "'" + ').value=document.getElementById(' + "'firstopt1'" + ').value; document.getElementById(' + "'select" + vars[ivars] + "'" + ').style.display=' + "'block'" + '; ';
thisih+=' document.getElementById(' + "'select" + vars[ivars] + "'" + ').style.display=' + "'block'" + '; ';
if (newnewt == '') {
document.getElementById('select' + vars[ivars]).value="document.getElementById('mybody')";
}
seloc(document.getElementById('select' + vars[ivars]));
}
} else {
if (vars[ivars].trim() != '') {
document.getElementById('i' + vars[ivars]).style.display='block';
if (newnewt == '') {
document.getElementById('i' + vars[ivars]).value='';
}
thisih+=' document.getElementById(' + "'i" + vars[ivars] + "'" + ').value=' + "'' + " + vars[ivars] + '; document.getElementById(' + "'i" + vars[ivars] + "'" + ').style.display=' + "'block'" + '; ';
} else {
if (curobj) { repone='window.'; repthree='lasto=lasto.'; }
thisih+=' ';
}
}
}
}
if (newt.indexOf(tv.split('(')[1].split(')')[0] + ')') != -1) {
suff=newt.split(tv.split('(')[1].split(')')[0] + ')')[eval(-1 + newt.split(tv.split('(')[1].split(')')[0] + ')').length)].split('}')[0];
}
//suff+=' valnone(); ';
nts=newt.split('(one,');
if (newt.indexOf('window.') != -1) {
newt=newt.replace('getComputedStyle(one,two);', 'getComputedStyle(one); console.log(lasto.getPropertyValue(two));');
thisih+=(' ' + newt.split('{')[1].split('window.')[0] + ' ' + tv.split('(')[0] + '(' + tv.split('(')[1].split(')')[0].trim() + ')' + suff + ' ');
} else {
thisih+=' ' + tv.split('(')[0] + '(' + tv.split('(')[1].split(')')[0].trim() + ')' + suff + ' ';
}
if (document.getElementById('myselect').value.indexOf('al(one)') != -1 && 1 == 3) {
newt=newt.replace('(one,' + nts[eval(-1 + nts.length)], '(eval(' + document.getElementById('selectone').value + '),' + nts[eval(-1 + nts.length)]);
}
newt=newt.replace(repone,reptwo).replace(repthree,repfour).replace(/\(\ \)/g,'()');
if (newt.indexOf(' lasto.') != -1) {
if (thisih.indexOf(' ' + tv.split('(')[0] + '(') != -1) {
thisih=thisih.replace(' ' + tv.split('(')[0] + '(', ' lasto.' + tv.split('(')[0] + '(');
}
}
document.getElementById('myh4').innerHTML="<a title='Double click to make happen' ondblclick=\" setTimeout(aftdbl,2000); " + thisih + "\" style=text-decoration:underline;cursor:pointer;>" + newt + "</a>";
if (newnewt == '') {
myh4ih=document.getElementById('myh4').innerHTML;
}
eval(newt);
}
}
function aftdbl() {
document.getElementById('myh4').style.backgroundColor='lightgray';
}
function changeyours(divo) {
var tih=(divo.innerText || divo.contentWindow || divo.contentDocument);
//alert('tih=' + tih);
if (tih.indexOf('(function') != -1 && document.getElementById('selectone').value.indexOf('function') == 0) {
eval('one=function' + tih.split('(function')[1].split('}')[0] + '}');
document.getElementById('optionfunction').innerHTML='function' + tih.split('(function')[1].split('}')[0] + '}';
divo.innerHTML=myh4ih;
tih=(divo.innerText || divo.contentWindow || divo.contentDocument);
}
if (tih.indexOf('window.') != -1) {
//alert('arg 1=' + tih.split('window.')[1].split(';')[0]);
setitup(tih.split('window.')[1].split(';')[0], tih);
} else {
//alert('Arg 1=' + document.getElementById('myselect').value);
setitup(document.getElementById('myselect').value, tih);
}
}
function valnone() {
document.getElementById('selectone').style.display='none';
document.getElementById('ione').style.display='none';
document.getElementById('itwo').style.display='none';
document.getElementById('ithree').style.display='none';
document.getElementById('ifour').style.display='none';
}
function onl() {
var idsare=document.body.outerHTML.split(' id="');
for (var jids=1; jids<idsare.length; jids++) {
if (jids == 1) {
document.getElementById('selectone').innerHTML+="<option id=firstopt" + jids + " value=\"document.getElementById('" + idsare[jids].split('"')[0] + "')\">" + idsare[jids].split('"')[0] + "</option>";
} else {
document.getElementById('selectone').innerHTML+="<option id=firstopt" + jids + " value=\"document.getElementById('" + idsare[jids].split('"')[0] + "')\">" + idsare[jids].split('"')[0] + "</option>";
}
}
document.getElementById('selectone').innerHTML+="<option id=optionlasto value='lasto'>lasto</option>";
document.getElementById('selectone').innerHTML+="<option id=optionfunction title=\"As required, we will honour any function(){ } rewrite you make instead of rightmost yellow 'one' below, and reflect this back here.\" value='function(){ console.log( (new Date() ) ); }'>function(){ console.log( (new Date() ) ); }</option>";
}
function seloc(selo) {
if (('' + selo.options[selo.selectedIndex].title).replace('null','').replace('undefined','') != '') {
selo.title='one ... ' + selo.options[selo.selectedIndex].title;
eval("one=" + selo.options[selo.selectedIndex].innerHTML); //outerHTML.split('>')[1].split('<')[0]);
} else if (('' + selo.options[selo.selectedIndex].id).replace('null','').replace('undefined','').indexOf('firstopt') == 0 || 1 == 1) {
selo.title="one = " + document.getElementById('selectone').value + ";";
} else {
selo.title='one';
}
return selo;
}
</script>
</head>
<body id=mybody onload="onl();">
<h1 id=myh1>Window Object Methods</h1>
<h2 id=myh2>RJM Programming - June, 2022</h2>
<h3 id=myh3>Thanks to <a id=mya target=_blank href='//www.w3schools.com/jsref/obj_window.asp' title='https://www.w3schools.com/jsref/obj_window.asp'>https://www.w3schools.com/jsref/obj_window.asp</a></h3>
<select id=selectone style=display:none; title='one' onchange="seloc(this); one=eval(this.value);"><option id=optionwindow value='window'>Please choose an element name or object [window] ...</option></select><textarea rows=1 cols=200 onblur="one=this.value;" style="display:none;width:80%;" id=ione placeholder="one" type="text" value=""></textarea>
<input onblur="two=this.value;" style="display:none;width:80%;" id=itwo placeholder="two" type="text" value=""></input>
<input onblur="three=this.value;" style="display:none;width:80%;" id=ithree placeholder="three" type="text" value=""></input>
<input onblur="four=this.value;" style="display:none;width:80%;" id=ifour placeholder="four" type="text" value=""></input>
<h4 id=myh4 contenteditable=true onblur='changeyours(this);'>Will show here your Javascript code happening.</h4>
<br>
<select id=myselect onchange="valnone(); setitup(this.value,'');"><option value=''>Please choose a Window Object method to make your own ...</option>
<option value="alert(one)">alert() Displays an alert box with a message and an OK button</option>
<option value="atob(one)">atob() Decodes a base-64 encoded string</option>
<option value="blur( )">blur() Removes focus from the current window</option>
<option value="btoa(one)">btoa() Encodes a string in base-64</option>
<option value="clearInterval(Eval(one))">clearInterval() Clears a timer set with setInterval</option>
<option value="clearTimeout(Eval(one))">clearTimeout() Clears a timer set with setTimeout</option>
<option value="close( )">close() Closes the current window</option>
<option value="confirm(one)">confirm() Displays a dialog box with a message and an OK and a Cancel button</option>
<option value="focus( )">focus() Sets focus to the current window</option>
<option value="getComputedStyle(eval(one),two)">getComputedStyle() Gets the current computed CSS styles applied to an element</option>
<option value="getSelection( )">getSelection() Returns a Selection object representing the range of text selected by the user</option>
<option value="matchMedia(one)">matchMedia() Returns a MediaQueryList object representing the specified CSS media query string</option>
<option value="moveBy(one,two)">moveBy() Moves a window relative to its current position</option>
<option value="moveTo(one,two)">moveTo() Moves a window to the specified position</option>
<option value="open(one,two,three)">open() Opens a new browser window</option>
<option value="print( )">print() Prints the content of the current window</option>
<option value="prompt(one,two)">prompt() Displays a dialog box that prompts the visitor for input</option>
<option value="requestAnimationFrame(EVal(one))">requestAnimationFrame() Requests the browser to call a function to update an animation before the next repaint</option>
<option value="resizeBy(one,two)">resizeBy() Resizes the window by the specified pixels</option>
<option value="resizeTo(one,two)">resizeTo() Resizes the window to the specified width and height</option>
<option value="scroll(one,two)">scroll() Deprecated. This method has been replaced by the scrollTo method.</option>
<option value="scrollBy(one,two)">scrollBy() Scrolls the document by the specified number of pixels</option>
<option value="scrollTo(one,two)">scrollTo() Scrolls the document to the specified coordinates</option>
<option value="setInterval(EVal(one),two)">setInterval() Calls a function or evaluates an expression at specified intervals (in milliseconds)</option>
<option value="setTimeout(EVal(one),two)">setTimeout() Calls a function or evaluates an expression after a specified number of milliseconds</option>
<option value="stop( )">stop() Stops the window from loading</option>
</select>