Javascript document.querySelectorAll User Scripting Tutorial
โœ‚๐Ÿƒ๐Ÿพโ€โ™€๏ธ๐Ÿƒ๐Ÿผโ€โ™‚๏ธ
๐Ÿ“–

Javascript document.querySelectorAll User Scripting Tutorial

Javascript document.querySelectorAll User Scripting Tutorial   ๐Ÿ”

Another user defined feature we can add to yesterdayโ€™s Javascript document.querySelectorAll Absolute URL Tutorialโ€˜s functionality list of โ€ฆ

  • CSS user defined selector default styling for relative URL
  • CSS user defined styling for relative URL
  • Onclick logic related to that CSS selector via Javascript document.querySelectorAll for relative URL
  • Popup window or refresh mode child iframe src then srcdoc overlay techniques for relative URL that is nothing (ie. this web application)
  • Absolute URL support as per the top three functionalities above โ€ฆ is, today, we have added โ€ฆ
  • User defined Javascript scripting (with the ` character delimiter added in case styling or scripting requires the # character)

Yes, Javascript can be user defined and dynamic in an already running execution via Javascript such as โ€ฆ



<head>

<script type='text/javascript'>

var thejs=location.search.split("thescript=")[1] ? decodeURIComponent(location.search.split("thescript=")[1].split('&')[0]).replace(/\;\ /g, '; ' + String.fromCharCode(10)) : "";



function onl(injs) {

if (injs.trim() != '') {

var tag = document.createElement('script');

tag.type='text/javascript';

tag.src='data:text/javascript;base64,' + btoa(injs);

document.head.appendChild(tag);

}

}


</script>

</head>

<body onload="document.getElementById('myinput').focus(); onl(thejs);">

Using thischanged qsallโšซhtmโ€˜s liveโœ‚run linkโ€™s functionalities, we can โ€ฆ

Use dynamically added Javascript to add three dots to top header



Previous relevant Javascript document.querySelectorAll Absolute URL Tutorial is shown below.

Javascript document.querySelectorAll Absolute URL Tutorial

Javascript document.querySelectorAll Absolute URL Tutorial   ๐Ÿ”

Just quietly, we add onto the functionality of yesterdayโ€™s Javascript document.querySelectorAll Client Pre-emptive Iframe Tutorialโ€˜s work with the tolerance for the user to try some absolute URL entries as they try thechanged qsallโšซhtm liveโœ‚run link.

As we so often find ourselves doing these days we use the โ€œmidairโ€ feeling Ajax/FormData techniques to attempt to satisfy the user interactions, as per โ€ฆ



var wasino=null;

var absval='';

var urltosend='';

var zhr=null;

var wasplaceholder='';



function showStuff(evt) {

if (zhr.readyState == 4) {

if (zhr.status == 200) {

absval=zhr.responseText;

//alert(absval);

}

}

}




function ajaxit() {

zhr = new XMLHttpRequest();

var form=new FormData();

form.append('inurl', urltosend);

form.append('tdinto', 'divinv');

if (document.URL.indexOf('localhost:8888') != -1) {

zhr.open('post', '//localhost:8888/fgc/', true);

} else {

zhr.open('post', '//www.rjmprogramming.com.au/PHP/fgc/', true);

}

zhr.onreadystatechange = showStuff;

zhr.send(form);

preshowBelow();

}




function preshowBelow() {

if (absval != '') {

wasino.value=wasino.placeholder;

wasino.placeholder=wasplaceholder;

showBelow(wasino);

wasino=null;

absval='';

} else {

setTimeout(preshowBelow, 2000);

}

}




function showBelow(ino) {

var his='', bahis='';

if (wasplaceholder == '') {

wasplaceholder=ino.placeholder;

}

if (('' + ino.value).toLowerCase().indexOf('//') == 0) {

ino.value=document.URL.split(':')[0].toLowerCase() + ':' + ino.value;

} else if (('' + ino.value).toLowerCase().indexOf('www.') == 0) {

ino.value=document.URL.split(':')[0].toLowerCase() + '://' + ino.value;

}

if (('' + ino.value).toLowerCase().indexOf('http') == 0) {

if (absval == '') {

urltosend=ino.value.split('#')[0];

ino.placeholder=ino.value;

ino.value=''; //ino.value.replace(urlis,'');

wasino=ino;

ajaxit();

return;

}

}


if (ino.value.indexOf('#') != -1) {

if (('' + ino.value).indexOf(('' + ino.value).trim() + ' ') != -1) {

if (documentURL.indexOf('?') != -1) {

documentURL=documentURL.replace('?', '?window=popup&');

} else {

documentURL+='?window=popup';

}

} else if (('' + ino.value).indexOf(('' + ino.value).trim() + ' ') != -1) {

if (documentURL.indexOf('?') != -1) {

documentURL=documentURL.replace('?', '?window=y&');

} else {

documentURL+='?window=y';

}

} else if (('' + ino.value).indexOf(('' + ino.value).trim() + ' ') != -1) {

if (documentURL.indexOf('?') != -1) {

documentURL=documentURL.replace('?', '?refresh=y&');

} else {

documentURL+='?refresh=y';

}

}

if (ourdecodeURIComponent(ino.value.substring(eval(1 + ino.value.indexOf('#'))).replace(/NO\%WAY/g, 'NO%25WAY')).indexOf('{') != -1) {

selectorplusis=ourdecodeURIComponent(ino.value.substring(eval(1 + ino.value.indexOf('#'))).replace(/NO\%WAY/g, 'NO%25WAY'));

}

selectoris=ourdecodeURIComponent(ino.value.substring(eval(1 + ino.value.indexOf('#'))).replace(/NO\%WAY/g, 'NO%25WAY')).split('{')[0].trim();

}

if (ino.value.trim() != '') {

if (absval != '') {

bahis='data:text/html;base64,' + absval;

//alert(bahis);

absval='';

document.getElementById('ifgoeshere').innerHTML="<iframe id=ifsd onload='checkif(this);' style='position:absolute;top:0px;left:0px;width:100%;height:100%;z-index:7;' srcdoc=\"\"></iframe><iframe id=xifsd onload='checkif(this);' style='display:none;' src=\"" + bahis + "\"></iframe>";

} else
if (ino.value.split('#')[0].trim() == '' && 1 == 2) {

document.getElementById('myh1').style.opacity='0.01';

document.getElementById('myh3').style.opacity='0.01';

document.getElementById('myinput').style.opacity='0.01';

document.getElementById('ifgoeshere').innerHTML="<iframe onload='checkif(this);' style='position:absolute;top:0px;left:0px;width:100%;height:100%;z-index:7;' src='" + document.URL + "'></iframe>";

} else if (ino.value.split('#')[0].trim() == '') {

his='<html>' + document.head.outerHTML + document.body.outerHTML + '</html>';

bahis='data:text/html;base64,' + btoa(his);

document.getElementById('ifgoeshere').innerHTML="<iframe id=ifsd onload='checkif(this);' style='position:absolute;top:0px;left:0px;width:100%;height:100%;z-index:7;' srcdoc=\"\"></iframe><iframe id=xifsd onload='checkif(this);' style='display:none;' src=\"" + bahis + "\"></iframe>";

} else {

document.getElementById('myh1').style.opacity='0.01';

document.getElementById('myh3').style.opacity='0.01';

document.getElementById('myinput').style.opacity='0.01';

document.getElementById('ifgoeshere').innerHTML="<iframe onload='checkif(this);' style='position:absolute;top:0px;left:0px;width:100%;height:100%;z-index:7;' src='" + ino.value.split('#')[0].trim() + "'></iframe>";

}

}

}


Previous relevant Javascript document.querySelectorAll Client Pre-emptive Iframe Tutorial is shown below.

Javascript document.querySelectorAll Client Pre-emptive Iframe Tutorial

Javascript document.querySelectorAll Client Pre-emptive Iframe Tutorial   ๐Ÿ”

Many web applications we present at this blog use what we refer to โ€œinhouseโ€ as โ€ฆ



Client Pre-emptive Iframe

โ€ฆ as that โ€œsuck it and seeโ€ client approach to do some of the โ€œif it exists try itโ€ functionality you might think has to involve a serverside language like PHP. No, all the discussion below, ignores serverside anything, but instead dwells on โ€ฆ

  • โ€œchildโ€ iframe (leaning towards that Client Pre-emptive Iframe) making use of the โ€œfresh startโ€ their โ€œonloadโ€ event (and to a lesser extent โ€œonerrorโ€) provides the client (only) programmer โ€ฆ
  • initially via โ€œsrcโ€ attribute โ€ฆ but new to todayโ€™s work (at least for us, that we can remember) โ€ฆ
  • initially involve src=โ€data:text/html;base64,[base64HTMLContent]โ€ that โ€ฆ
  • (same) โ€œonloadโ€ code can redirect that content to another โ€œchildโ€ iframe (leaning towards that Client Pre-emptive Iframe) โ€œsrcdocโ€ attribute โ€ฆ and yes, we were not sure until today, but yes โ€ฆ
  • โ€œchildโ€ iframe (leaning towards that Client Pre-emptive Iframe) that gets its content via โ€œsrcdocโ€ attribute does pass through the โ€œonloadโ€ event logic where the โ€œdocumentโ€ object exists (a very happy discovery for us (though weโ€™ve probably been assuming it already in projects up to now))

โ€ฆ this โ€œproof of conceptโ€ experimenting being incorporated into our โ€œJavascript document.querySelectorAllโ€ project for scenarios โ€ฆ

For relative URL that is blank (ie. uses this same webpage) suffixes of two blanks refreshes and that of four blanks opens new window and that of eight blanks opens new popup window.

โ€ฆ to the point where you may not notice the difference between this โ€œsrcdocโ€ processing compared to the other (single) โ€œsrcโ€ attribute executions of the web application.

How does the client wooooooorrrrrrrllllllldddd handle base64? Well, for simple data โ€ฆ

Why canโ€™t we manage this new functionality in the one pass through the โ€œonloadโ€ event logic? Well, any self-respecting webpage content will contain both apostrophe and double quote characters (let alone line feeds and carriage returns) ( but we can if we can get to a Javascript DOM statement like document.getElementById(โ€˜ifsdโ€™).srcdoc=atob((โ€ + ioissrc).split(โ€˜;base64,โ€™)[1]).replace(โ€˜</boโ€™ + โ€˜dy>โ€™, โ€˜ <style> โ€˜ + selectorplusis + โ€˜</style> </boโ€™ + โ€˜dy>โ€™); ), making it hard to specify on the Javascript codeline constructing your โ€œchildโ€ iframe but now this new functionality uses โ€ฆ



var documentURL='' + document.URL.split('#')[0];




function showBelow(ino) {

if (ino.value.indexOf('#') != -1) {

if (('' + ino.value).indexOf(('' + ino.value).trim() + ' ') != -1) {

if (documentURL.indexOf('?') != -1) {

documentURL=documentURL.replace('?', '?window=popup&');

} else {

documentURL+='?window=popup';

}

} else if (('' + ino.value).indexOf(('' + ino.value).trim() + ' ') != -1) {

if (documentURL.indexOf('?') != -1) {

documentURL=documentURL.replace('?', '?window=y&');

} else {

documentURL+='?window=y';

}

} else if (('' + ino.value).indexOf(('' + ino.value).trim() + ' ') != -1) {

if (documentURL.indexOf('?') != -1) {

documentURL=documentURL.replace('?', '?refresh=y&');

} else {

documentURL+='?refresh=y';

}

}


if (ourdecodeURIComponent(ino.value.substring(eval(1 + ino.value.indexOf('#'))).replace(/NO\%WAY/g, 'NO%25WAY')).indexOf('{') != -1) {

selectorplusis=ourdecodeURIComponent(ino.value.substring(eval(1 + ino.value.indexOf('#'))).replace(/NO\%WAY/g, 'NO%25WAY'));

}

selectoris=ourdecodeURIComponent(ino.value.substring(eval(1 + ino.value.indexOf('#'))).replace(/NO\%WAY/g, 'NO%25WAY')).split('{')[0].trim();

}

if (ino.value.trim() != '') {

if (ino.value.split('#')[0].trim() == '' && 1 == 2) {

document.getElementById('myh1').style.opacity='0.01';

document.getElementById('myh3').style.opacity='0.01';

document.getElementById('myinput').style.opacity='0.01';

document.getElementById('ifgoeshere').innerHTML="<iframe onload='checkif(this);' style='position:absolute;top:0px;left:0px;width:100%;height:100%;z-index:7;' src='" + document.URL + "'></iframe>";

} else if (ino.value.split('#')[0].trim() == '') {

var his='<html>' + document.head.outerHTML + document.body.outerHTML + '</html>';

var bahis='data:text/html;base64,' + btoa(his);

document.getElementById('ifgoeshere').innerHTML="<iframe id=ifsd onload='checkif(this);' style='position:absolute;top:0px;left:0px;width:100%;height:100%;z-index:7;' srcdoc=\"\"></iframe><iframe id=xifsd onload='checkif(this);' style='display:none;' src=\"" + bahis + "\"></iframe>";

} else {

document.getElementById('myh1').style.opacity='0.01';

document.getElementById('myh3').style.opacity='0.01';

document.getElementById('myinput').style.opacity='0.01';

document.getElementById('ifgoeshere').innerHTML="<iframe onload='checkif(this);' style='position:absolute;top:0px;left:0px;width:100%;height:100%;z-index:7;' src='" + ino.value.split('#')[0].trim() + "'></iframe>";

}

}

}




function checkif(iois) {

var ij, wois=null;

if (iois != null) {

console.log('' + iois.src);

if (('' + iois.src).indexOf('data:') == 0 && ('' + iois.src).indexOf(';base64,') != -1) { // src=data:text/html;base64,[base64HTMLContent] comes here

var ioissrc=('' + iois.src);

iois.src='';

if (selectorplusis.indexOf(' BORDER') != -1) {

eles=document.querySelectorAll(selectoris);

for (ij=eval(-1 + eles.length); ij>=0; ij--) {

froms.push(eles[ij].outerHTML);

tos.push('<a onclick="alert(this.innerHTML);" style="cursor:pointer;text-decoration:none;" title="Border clickable">' + eles[ij].outerHTML + '</a>');

}

for (ij=0; ij<froms.length; ij++) {

ioissrc=ioissrc.replace(froms[ij], tos[ij]);

}

}

var xbodyt=atob(('' + ioissrc).split(';base64,')[1]).replace('</bo' + 'dy>', ' <style> ' + selectorplusis + '</style> </bo' + 'dy>');

var bodyt=xbodyt.split('<bo' + 'dy')[1];

if (('' + documentURL).indexOf('window=') != -1) {

if (('' + documentURL).indexOf('popup') != -1) {

wois=window.open('', '_blank', 'top=0, left=0, width=600, height=600');

} else {

wois=window.open('', '_blank');

}

wois.document.write(atob(('' + ioissrc).split(';base64,')[1]).replace('</bo' + 'dy>', ' <style> ' + selectorplusis + '</style> </bo' + 'dy>'));

} else if (('' + documentURL).indexOf('refresh=') != -1) {

document.body.innerHTML=bodyt.substring(eval(1 + bodyt.indexOf('>'))).split('</bo' + 'dy>')[0];

} else {

document.getElementById('myh1').style.opacity='0.01';

document.getElementById('myh3').style.opacity='0.01';

document.getElementById('myinput').style.opacity='0.01';

document.getElementById('ifsd').srcdoc=atob(('' + ioissrc).split(';base64,')[1]).replace('</bo' + 'dy>', ' <style> ' + selectorplusis + '</style> </bo' + 'dy>');

}

} else {
// relative URL src comes here, as well as srcdoc (we have discovered today 23/1/2021)

console.log(1);

var aconto = (iois.contentWindow || iois.contentDocument);

console.log(2);

if (aconto != null) {

console.log(3);

//console.log(aconto);

console.log(4);

if (aconto.document) { aconto = aconto.document; }

console.log(5);

if (selectoris != '') {

console.log(6);

if (selectorplusis != '') {

console.log(7);

aconto.body.innerHTML+=' <style> ' + selectorplusis + '</style> ';

console.log(8);

if (selectorplusis.indexOf(' BORDER') != -1) {

console.log(9);

eles=aconto.querySelectorAll(selectoris);

for (ij=eval(-1 + eles.length); ij>=0; ij--) {

froms.push(eles[ij].outerHTML);

tos.push('<a onclick="alert(this.innerHTML);" style="cursor:pointer;text-decoration:none;" title="Border clickable">' + eles[ij].outerHTML + '</a>');

}

for (ij=0; ij<froms.length; ij++) {

aconto.body.innerHTML=aconto.body.innerHTML.replace(froms[ij], tos[ij]);

}

}

} else {

console.log('a');

eles=aconto.querySelectorAll(selectoris);

console.log('b');

for (ij=0; ij<eles.length; ij++) {

eles[ij].style.border='1px dashed red';

}

}

}

}

}

}

}

We hope you revisit the recent Javascript document.querySelectorAll User Styled Clickable Border Tutorialโ€˜s improvements todayโ€™s work represents inthe changed qsallโšซhtm liveโœ‚run link is worth it to try the (Pure) Javascript meets CSS ideas above.


Previous relevant Javascript document.querySelectorAll User Styled Clickable Border Tutorial is shown below.

Javascript document.querySelectorAll User Styled Clickable Border Tutorial

Javascript document.querySelectorAll User Styled Clickable Border Tutorial   ๐Ÿ”

Yesterdayโ€™s Javascript document.querySelectorAll Primer Tutorial has been โ€œstretchedโ€ in functionality in two ways โ€ฆ

  • yesterdayโ€™s user defined selector but static styling is now opened up to user defined styling as well โ€ฆ
  • we wanted to allow a user defined CSS styling that involves the use of โ€ BORDERโ€ somewhere adds border clickable elements that satisfy the selector criteria used in โ€ฆ



function checkif(iois) {

var ij;

if (iois != null) {

var aconto = (iois.contentWindow || iois.contentDocument);

if (aconto != null) {

if (aconto.document) { aconto = aconto.document; }

if (selectoris != '') {

if (selectorplusis != '') {

aconto.body.innerHTML+=' <style> ' + selectorplusis + '</style> ';

if (selectorplusis.indexOf(' BORDER') != -1) {

eles=aconto.querySelectorAll(selectoris);

for (ij=eval(-1 + eles.length); ij>=0; ij--) {

froms.push(eles[ij].outerHTML);

tos.push('<a onclick="alert(this.innerHTML);" style="cursor:pointer;text-decoration:none;" title="Border clickable">' + eles[ij].outerHTML + '</a>');

}

for (ij=0; ij<froms.length; ij++) {

aconto.body.innerHTML=aconto.body.innerHTML.replace(froms[ij], tos[ij]);

}

}

} else {

eles=aconto.querySelectorAll(selectoris);

for (ij=0; ij<eles.length; ij++) {

eles[ij].style.border='1px dashed red';

}

}

}

}

}

}

Yes, we needed to ask for help, and got good help here, thanks (for that doh! moment).

Todayโ€™schanged liveโœ‚run link is worth it to try the (Pure) Javascript meets CSS ideas above.


Previous relevant Javascript document.querySelectorAll Primer Tutorial is shown below.

Javascript document.querySelectorAll Primer Tutorial

Javascript document.querySelectorAll Primer Tutorial   ๐Ÿ”

โ€œPure Javascriptโ€ versus โ€œjQueryโ€ is an issue for many developers of client side web application code logic. More often than not we plump for the former, though there are notable exceptions for us, such as jQuery Ajax is often of use, and we have used the very apt (for todayโ€™s topic) jQuery CSS on occasions. But for todayโ€™s proof of concept test run of โ€ฆ



document.querySelectorAll([CSS-selector]);

โ€ฆ itโ€™s all โ€œPure Javascriptโ€. In todayโ€™s qsallโšซhtml HTML and โ€œPure Javascriptโ€ code you will not find the string โ€œdocument.querySelectorAllโ€ anywhere because our web application is โ€ฆ

  • just some header HTML elements and one HTML input type=text โ€œtextboxโ€ element and one containing div element and one input type=text to avoid โ€œtabbing outโ€ annoyances โ€ฆ
  • โ€œtextboxโ€ accepts a relative URL in two parts as per โ€ฆ


    [relativeURLTo-//www.rjmprogramming.com.au/]#[CSS-selector]

  • that relative URL is the โ€œsrcโ€ attribute to an HTML iframe element that overlays (made to be barely visible) header HTML elements and one HTML input type=text โ€œtextboxโ€ element โ€ฆ and whose โ€ฆ
  • โ€œonloadโ€ event logic goes โ€ฆ


    function checkif(iois) {

    var ij;

    if (iois != null) {

    var aconto = (iois.contentWindow || iois.contentDocument);

    if (aconto != null) {

    if (aconto.document) { aconto = aconto.document; }

    if (selectoris != '') {

    eles=aconto.querySelectorAll(selectoris);

    for (ij=0; ij<eles.length; ij++) {

    eles[ij].style.border='1px dashed red';

    }

    }

    }

    }

    }

โ€ฆ that you can try for yourself with todayโ€™s liveโœ‚run link.

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

This entry was posted in eLearning, Event-Driven Programming, Tutorials and tagged , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *