Why, with todayโs tutorial, are we conflating two quite disparate subjects โฆ
- HTTP (ie. Hypertext Transfer Protocol) Error Code 404 โPage Not Foundโ or โServer Not Foundโ โฆwith โฆ
- Email Subject lines
โฆ into the one tutorial topic? Well, as we talked about with body of email scenarios, with some email clients (with Window SessionStorage Client Versus Server CSS Tutorial) โฆ
As far as links go, you may expect to need serverside means to construct these in online Email and SMS message interfacing, but email (client program) products like Gmail parse your ascii text and convert http: or https: protocol URLs in your Email body to hyperlinks, as does the Messages SMS application here on this MacBook Pro using macOS Mojave.
โฆ it pans out with some email clients such as iOS Mail app, that email subject lines containing similar http: or https: protocol URLs also get converted into hyperlinks. For us this has become a more likely scenario ever since the email [date] subject line token work typified by Local Datetime Token Subject Integrations Tutorial. The nature of those hyperlinks created, though, seem to be a great concern for these more helpful email clients and if you put into subject lines URLs containing โ?โ and โ&โ delimited arguments, the email clients mildly โmash upโ these URLs so that recent ones from our โPlot Axes โ Linear or Parabolic Formulaโ web application for (an example like) โฆ
โฆ on email clients that do not do โthe (monster) mashโ, on an email client that โdoes hyperlink but mash upโ the URL the email subject line takes you to is actually (an additional โlayer of encodeURIComponentโed contentโ you can see as you hover over the link, the display normalized as far as looks go, via HTML entity mapping) โฆ
โฆ which, without the tailoring of RJM Programming domainโs Error 404 trapping 404.shtml would not take you to its true destination (of look) โฆ because of โthe mashโ.
Itโs been a while since we set up this 404.shtml Apache web server means to serve โNot Foundโ (Page) URLs with a more welcoming experience than the default web browser โError 404 โฆ Not Foundโ kind of error message, so we started our research into whether it was possible to redirect from a 404.shtml on an Apache web server at this useful Google search, thanks.
Now, it must be noted here, that the search engines may penalise you for making the 404.shtml redirection we are going to show you below. Honestly, we donโt know, but we feel compelled to let you know that such a redirection is possible on an Apache web serverโs 404.shtml with a document.body โonloadโ changed event (HTML and Javascript code snippet) piece of logic as below โฆ
<script type='text/javascript'>
function onPageUnload() {
}
function onPageLoad() {
if (document.URL.indexOf('square_hr_tracing.htm%') != -1) {
location.href=document.URL.replace('%3F','?').replace(/\%23/g, '#').replace(/\%26/g, '&');
exit;
}
}
</script>
</head>
<body style="background: #d4d4d4; margin: 0pt; " onload="onPageLoad();" onunload="onPageUnload();">
โฆ that is helping make sense of the โmashed upโ URL (from some email client subject lines) above, as well as the rest of this 404.shtml (placed into RJM Programming domainโs Document Root) showing a more friendly webpage for all those misdirected URLs such as this one.
Previous relevant Window SessionStorage Client Versus Server CSS Tutorial is shown below.
Further to yesterdayโs Window SessionStorage Client Versus Server Integration Tutorial we have a two pronged improvements set for you today with our current Capital City Find Matching Country Report web application project โฆ
- CSS styling changes โฆ and โฆ
- additional functionality for Email and SMS links back to our current Capital City Find Matching Country Report web application project (to complete the cycle)
We use several modes of CSS application (the first and last of particular relevance to todayโs โhighlighting of workflowโ improvements) โฆ
- โstaticโ internal CSS coding within thechanged wls_vs_php
htmโs Capital
City Find Matching Country Report live run linkโs new CSS and linking improvements, which caused thechanged colour_wheel
htmlโs colour wheel (at this live
run link) to be affected (by integrations โupโ, opening up the Google Maps and YouTube interfacing emoji buttons there)
- โstaticโ internal HTML โstyleโ attribute styling
- โdynamicโ Javascript DOM HTML โstyleโ attribute changes
- โdynamicโ Javascript DOM โclassโ modifications to dovetail with the โstaticโ internal CSS coding as above
โฆ the โstaticโ measures often helping to highlight the web applicationโs main workflow of user interaction and the โdynamicโ measures helping to alert the user as to where to proceed with their โworkflowโ.
In terms of CSS styling work โฆ
- for non-mobile platforms we allow for more columns to be applied to our Capitals select (dropdown) element (in order to reduce some user scrolling, as does our new additional A-Z letter basis sorting functionality) as per โฆ the โdynamicโ Javascript DOM โclassโ modifications โฆ
if (!navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
document.getElementById('lefttd').className='lefttd';
}
โฆ dovetailing with the โstaticโ internal CSS coding โฆ
<style>
.lefttd {
column-count: 4;
max-height: 35%;
vertical-align: top;
max-width: 70%;
font-size: 8px;
background-color: rgba(205,205,205,0.5);
background-image: -webkit-gradient(
linear,
right bottom,
left top,
color-stop(0, rgba(205, 205, 205, 0.8)),
color-stop(0.50, rgba(255, 255, 0, 0.2))
);
background-image: -o-linear-gradient(left top, rgba(205, 205, 205, 1) 0%, rgba(255, 255, 0, 0.2) 50%);
background-image: -moz-linear-gradient(left top, rgba(205, 205, 205, 1) 0%, rgba(255, 255, 0, 0.2) 50%);
background-image: -webkit-linear-gradient(left top, rgba(205, 205, 205, 1) 0%, rgba(255, 255, 0, 0.2) 50%);
background-image: -ms-linear-gradient(left top, rgba(205, 205, 205, 1) 0%, rgba(255, 255, 0, 0.2) 50%);
background-image: linear-gradient(to left top, rgba(205, 205, 205, 1) 0%, rgba(255, 255, 0, 0.2) 50%);
}
</style>
โฆ and please note that around here at RJM Programming we have a โfar from hard and fast ruleโ (but a rule regardless) regarding HTML element ID and class attributes that they concern (and (usually) be compartmentalised into) Javascript (DOM) manipulations and CSS styling issues respectively โฆ and add a linear-gradient background to the table cell when expecting the initial user interaction on non-mobile platforms - a โdynamicโ Javascript DOM โclassโ modification โฆ document.getElementById(โmyrepsbโ).className=โdglowโ; โฆ is made to the โReportโฆโ button at the Capitals select (dropdown) onfocusout event so as to highlight (with โglowโ inspired styling) where user interaction may flow to
As far as links go, you may expect to need serverside means to construct these in online Email and SMS message interfacing, but email (client program) products like Gmail parse your ascii text and convert http: or https: protocol URLs in your Email body to hyperlinks, as does the Messages SMS application here on this MacBook Pro using macOS Mojave. Cute, huh?! So to close the circle back from remote tharโ parts back to our web application is a simple matter of, in broad brush terms โฆ
- adding two new buttons called โEmail Columns and Links โฆโ and โSMS Columns and Links โฆโ that โฆ
- set a global variable andlinkto = true; โฆ setting in play, within the report writing code (that likes monospaced fonts) โฆ
- add a new links column to the right with URLs like โฆ
https://www.rjmprogramming.com.au/HTMLCSS/wls_vs_php.htm?andgo=y&countries=Belize&capitals=Belmopan
โฆ to tell your client programs to form the hyperlinks for us (if they are โof the moodโ, that is!)
To improve user experience we use โdynamicโ Javascript DOM HTML โstyleโ attribute change means to easier close the โColour Wheelโ helper web application โabove the foldโ by changing the CSS z-index (Javascript DOM [element].style.zIndex) of elements accordingly, when the user clicks other elements. You can see all this with the first โthechangedโ link above, where all โglowโ CSS styling will also feature prominently.
Previous relevant Window SessionStorage Client Versus Server Integration Tutorial is shown below.
We hope, when performing a โsoftware integrationโ task, that the two or more components of that integration work with each otherโs talents, rather than a big tussle like reinventing the wheel. This ideal makes the work โฆ
- sometimes difficult but rewarding because โฆ
- the differences between two independent software components can be quite large and daunting โฆ and the programmer has to see that โฆ
- care is applied so as not to wreck previous functionality and integrations in making the current integration work
โฆ and that is why weโve made corollaries to โbuilding from scratchโ (when planning and design is a huge component) can be a lot simpler than a software integration โrenovationโ, in the past, here at this blog.
Our primary integration today is to (software) integrate the great Weather Underground and its great API service for autocomplete name searches for weather (and hurricane) information. Why bother? Well, can you not envisage a user using that Ajax functionality of yesterdayโs Window SessionStorage Client Versus Server Ajax Tutorial as a trip planner, perhaps, or as a โchecking up on relatives overseasโ tool, perhaps? And not all the capital cities are timezone places, and so for some of those we can use Weather integration to still show apt online information when click/touching a Countries Report row. Speaking of this โrowโ, we make an improvement whereby on a first click of a right hand (Country) row cell, that cell is not initially a contenteditable=โtrueโ one (that may frustrate showing the keyboard on mobile, when most likely it was the row touch intended), but then becomes a contenteditable=โtrueโ cell henceforth.
As a user experience improvement for โtrip plannersโ perhaps, we allow the user to alphabetically sort the presented select (dropdown) element entries โฆ
var firstopt='';
var wasopts='';
var restopts='';
function readyitforsort(iselid) {
var optsare=[];
var huhisel=document.getElementById(iselid).innerHTML;
var huhsopts=huhisel.split('</option>');
for (var ihuh=0; ihuh<huhsopts.length; ihuh++) {
if (huhsopts[ihuh].trim() != '') {
if (firstopt == '') {
firstopt=huhsopts[ihuh] + '</option>';
} else {
wasopts+=huhsopts[ihuh].replace('option ','option data-ih="' + (huhsopts[ihuh].split('>')[eval(-1 + huhsopts[ihuh].split('>').length)] + '" ')) + '</option>';
optsare.push(huhsopts[ihuh].replace('option ','option data-ih="' + (huhsopts[ihuh].split('>')[eval(-1 + huhsopts[ihuh].split('>').length)] + '" ')) + '</option>');
}
}
}
optsare.sort();
for (var jhuh=0; jhuh<optsare.length; jhuh++) {
restopts+=optsare[jhuh];
}
}
โฆ controlled by a new dropdown in the left hand column header cell.
We also allow the user to move the iframe element with some positioning emoji buttons near the โCloseโ button one (of yesterdayโs work).
Into the future, too, weโll have more to say regarding the germination of an idea โto allow a mobile onmouseover simulator (of sorts)โ be to allow the user to perform a swipe across an individual HTML element of interest on mobile platforms (ie. harness ontouchmove event) as per (so far) โฆ kicked off by โ<body onload=โ setTimeout(athn, 5000); โ>โ โฆ
var last24='';
var rectdc;
function nodivalert() {
document.getElementById('divalert').style.display='none';
document.getElementById('divalert').style.zIndex='-456';
document.getElementById('divalert').style.left=('-' + rectdc.left).replace('px','') + 'px';
document.getElementById('divalert').style.top=('-' + rectdc.top).replace('px','') + 'px';
}
function ourdivalert(inmsg) {
document.getElementById('divalert').style.position='absolute';
document.getElementById('divalert').style.left=('' + rectdc.left).replace('px','') + 'px';
document.getElementById('divalert').style.top='' + eval(-80 + eval(('' + rectdc.top).replace('px',''))) + 'px';
document.getElementById('divalert').style.backgroundColor='#e0e0e0';
document.getElementById('divalert').style.display='block';
document.getElementById('divalert').style.zIndex='456';
document.getElementById('divalert').style.opacity='0.8';
document.getElementById('divalert').style.padding='5px 5px 5px 5px';
document.getElementById('divalert').innerHTML=inmsg + '<br><br><input type=button value=Close onclick=nodivalert();></input>';
setTimeout(nodivalert,9000);
}
function athn() {
rectdc=document.getElementById('dc').getBoundingClientRect();
if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
document.getElementById('dc').ontouchmove=function(event) { if (last24.substring(0,eval(-1 + last24.length)) == event.target.title.substring(0,eval(-1 + event.target.title.length))) { last24=last24; } else { last24=event.target.title; ourdivalert(event.target.title); } }
} else {
document.getElementById('dc').onmousemove=function(event) { if (last24.substring(0,eval(-1 + last24.length)) == event.target.title.substring(0,eval(-1 + event.target.title.length))) { last24=last24; } else { last24=event.target.title; ourdivalert(event.target.title); } }
}
}
โฆ working with the new HTML โฆ
<div id=divalert></div>
</body>
</html>
โฆ to try to allow the โexplainer of an elementโ advantages non-mobile platforms have for hovering over an HTML element with a title attribute filled in.
And so, yet again, see thechanged wls_vs_phphtmโs Capital
City Find Matching Country Report live run linkโs new Weather integration functionality. It caused thechanged colour_wheel
htmlโs colour wheel (at this live
run link) to be affected (by integrations โupโ).
Previous relevant Window SessionStorage Client Versus Server Ajax Tutorial is shown below.
We have a few โclientside chestnutsโ to use with our current Capital City Find Matching Country Report web application project today, those being โฆ
- Ajax functionality, kicked off by an โonclickโ event set of logic, allowing mobile platforms to also have a look in (the look in that they miss when the event logic is off the โonmouseoverโ event)
- iframe and its โฆ
- srcdoc attribute (โcontentโ alternative to src โurlโ attribute) โฆ along with, and crucially needing (because srcdoc ignores its own document.body onload goings on, that we need the โIframe Client Pre-Emptiveโ methods below to circumvent) the โฆ
- onload event opportunity of an iframe element (we group into โIframe Client Pre-Emptiveโ methods, here)
โฆ adding onto yesterdayโs Window SessionStorage Client Versus Server Canvas Tutorial.
Itโs not that involved with the Ajax work today, given that there are no cross-domain issues, though there are cross-protocol (SSL https: versus non-SSL http:) issues to be careful about. Those can be addressed because the web application is recalled to present its โCountry Reportโ and that is the opportunity to check on protocol navigation requirements.
Along the way, we also make this happen for the user on โฆ
- click/touching a table row โฆ it sets off new โtrโ (table row) element logic calling our (inhouse) Timezone and Wikipedia Place Information helper (HTML) via Ajax (so not leaving the webpage) โฆ and because of place name oddities we allow for โฆ
- โtdโ (table cell) element user amendments by setting their contenteditable attributes to โtrueโ (since fixed, but we found the Timezone Europe/Tirane pointing at Tirane in Albania used to be spelt โTiranaโ)
โฆ that latter methodology normally a technique we apply to โdivโ elements (so, there you are!)
Also used are โoverlayโ techniques, two of the โusual suspectsโ here coming into play, to present to the โAjax content to srcdoc iframe arrangementsโ โฆ
- position:absolute property (with associated top and left (px defined) properties)
- z-index
Yet again, see thechanged wls_vs_phphtmโs Capital
City Find Matching Country Report live run linkโs new โAjaxโ functionality.
Previous relevant Window SessionStorage Client Versus Server Canvas Tutorial is shown below.
Yesterdayโs Window SessionStorage Client Versus Server Share Tutorial dealt with ascii text clipboard copy assisted sharing options with our current Capital City Find Matching Country Report web application project. This suited both Email and SMS share options we coded for, but todayโs extension of functionality from โascii textโ data to โgraphical dataโ only suits Email sharing. The other caveat with our work is that no serverside (for us, PHP) help is allowed, so no PHP mail here.
What comes into play with a โgraphical dataโ clientside (only) sharing approach? It will not surprise many readers that, for us, it involves โฆ
- canvas element โฆ converting HTML table outerHTML โascii textโ data โฆ via โฆ
- canvas drawing methods โ[canvasContext].strokeRect()โ and โ[canvasContext].strokeText()โ via โ[cellElement].getBoundingClientRect()โ โฆ to convert that canvas element content via โฆ
- [canvasElement].toDataURL() โฆ to an โฆ
- img element nested in a div contenteditable=true element โฆ so as to hook in with todayโs very useful helper link, thanks โฆ use โฆ
-
function tabletoclipboard(canvas) { // thanks to https://stackoverflow.com/questions/27863617/is-it-possible-to-copy-a-canvas-image-to-the-clipboard
var img = document.createElement('img');
img.src = canvas.toDataURL();
var div = document.createElement('div');
div.contentEditable = true;
div.appendChild(img);
document.body.appendChild(div);
// do copy
SelectText(div);
document.execCommand('Copy');
document.body.removeChild(div);
}
function SelectText(element) { // thanks to https://stackoverflow.com/questions/27863617/is-it-possible-to-copy-a-canvas-image-to-the-clipboard
var doc = document;
if (doc.body.createTextRange) {
var range = document.body.createTextRange();
range.moveToElementText(element);
range.select();
} else if (window.getSelection) {
var selection = window.getSelection();
var range = document.createRange();
range.selectNodeContents(element);
selection.removeAllRanges();
selection.addRange(range);
}
} - to leave the userโs deviceโs clipboard containing a useful table (with linework) โฆ ready to โฆ
- paste into an email body section
โฆ sharing off to an emailee collaborator.
Again, see thechanged wls_vs_phphtmโs Capital
City Find Matching Country Report live run linkโs new โEmail Tableโ button functionality.
Previous relevant Window SessionStorage Client Versus Server Share Tutorial is shown below.
Yesterdayโs Window SessionStorage Client Versus Server Tutorial has been amended today for two new sharing and collaboration options, those being โฆ
- SMS
โฆ but you may well be familiar with the restrictions on email and SMS client (program) approaches to this, coming from HTML โaโ link โmailto:โ and โsms:โ href property prefixes respectively. Weโre going to need help with the 800 odd character (length) restrictions with the (resultant) web address (bar) URL, but what? How about working off the great advice of this wonderful link, thanks, to copy what weโd have assembled into an ascii text Report into the characters contained by the userโs deviceโs clipboard?
function copytoclipboard(str) { // thanks to https://hackernoon.com/copying-text-to-clipboard-with-javascript-df4d4988697f
var el = document.createElement('textarea');
el.value = str;
el.setAttribute('readonly', '');
el.style.position = 'absolute';
el.style.left = '-9999px';
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
}
An issue that springs up here using such clipboard ascii text content, whenever you get the Font choice given to you, pick a monospaced Font like Courier New or โFixed Widthโ.
See thechanged wls_vs_phphtmโs Capital
City Find Matching Country Report live run linkโs new sharing functionality.
Previous relevant Window SessionStorage Client Versus Server Tutorial is shown below.
Sometimes itโs the case at this blog that weโd like to introduce a new topic, but do not do so, because we cannot show any real world (or real application) use of that concept. So it has been, up until now, with the concept of (web browser) window (object) sessionStorage property. But yesterdayโs Window LocalStorage Client Versus Server Primer Tutorial represented an opportunity akin to when Haleyโs Comet gets at its closest to the Earth โฆ while you see a chance, take it โฆ chance because of that nuance whereby we were not trying to store data for any other purpose than passing data onto โฆ
- a known entity โฆ ie. same web application โฆ at โฆ
- a known time โฆ ie. immediately
โฆ two conditions that make the code design โmarginallyโ more ideal for the window object property concept of sessionStorage rather than localStorage, in that any โฆ
localStorage.removeItem([knownLocalStorageName]);
โฆ becomes superfluous as with sessionStorage data will disappear between web browser sessions, anyway.
We offer this new concept as a non-default option of a select (dropdown) element replacement to the h1 element hardcoding โlocalStorageโ with thechanged wls_vs_phphtm Capital
City Find Matching Country Report live run. The other nuance of difference with sessionStorage usage is that in the document.body onload event logic, we may as well (as part of other changes) pre-emptively look for, and if there, respond to, any found sessionStorage data points, even without the user having flagged it specifically โฆ
var datamode='localStorage';
function checkforreport() {
var divcont='';
var dcaps, dctys, idis;
if (getcapitals == 'localStorage') {
if (window.localStorage) {
getcapitals=decodeURIComponent(localStorage.getItem('wls_vs_php_capitals')).replace(/\+/g,' ');
localStorage.removeItem('wls_vs_php_capitals');
} else {
getcapitals='';
}
} else if (getcapitals == 'sessionStorage') {
document.getElementById('smode').value=getcapitals;
datamode=getcapitals;
if (window.sessionStorage) {
getcapitals=decodeURIComponent(sessionStorage.getItem('wls_vs_php_capitals')).replace(/\+/g,' ');
} else {
getcapitals='';
}
} else if (getcapitals == '' && window.sessionStorage) {
getcapitals=decodeURIComponent(('' + sessionStorage.getItem('wls_vs_php_capitals')).replace(/^null$/g,'')).replace(/\+/g,' ');
if (getcapitals != '') {
document.getElementById('smode').value='sessionStorage';
datamode='sessionStorage';
}
}
if (getcountries == 'localStorage') {
if (window.localStorage) {
getcountries=decodeURIComponent(localStorage.getItem('wls_vs_php_countries')).replace(/\+/g,' ');
if (getcapitals.replace('localStorage','') != '' && getcountries.replace('localStorage','') != '') { document.getElementById('myh1').innerHTML+=' <font size=1>... yes, it was needed</font>'; }
localStorage.removeItem('wls_vs_php_countries');
} else {
getcountries='';
}
} else if (getcountries == 'sessionStorage') {
if (window.sessionStorage) {
getcountries=decodeURIComponent(sessionStorage.getItem('wls_vs_php_countries')).replace(/\+/g,' ');
if (getcapitals.replace('sessionStorage','') != '' && getcountries.replace('sessionStorage','') != '') { document.getElementById('myh1').innerHTML+=' <font size=1>... yes, it was needed</font>'; }
} else {
getcountries='';
}
} else if (getcountries == '' && document.getElementById('smode').value == 'sessionStorage' && window.sessionStorage) {
getcountries=decodeURIComponent(('' + sessionStorage.getItem('wls_vs_php_countries')).replace(/^null$/g,'')).replace(/\+/g,' ');
if (getcountries != '') {
document.getElementById('smode').value='sessionStorage';
datamode='sessionStorage';
}
}
if (getcapitals != '' && getcountries != '') {
divcont='<table border=5 style="width:95%;vertical-align:top;background-color:white;"><tr style=background-color:#f0f0f0;"><th>Capital</th><th>Country</th></tr></table>';
dcaps=getcapitals.split('|');
dctys=getcountries.split('|');
for (idis=0; idis<dcaps.length; idis++) {
divcont=divcont.replace('</table>', '<tr><td>' + dcaps[idis] + '</td><td>' + dctys[idis] + '</td></tr></table>');
}
document.getElementById('dreport').innerHTML=divcont;
}
document.getElementById('smode').value=datamode;
}
Which beggars the question โWhat are the differences between sessionStorage and localStorage?โ A quick reading might surmise that โthe latter has an expiration dateโ. We leave you with an open ended Google search so that you may extend your readings on this.
Previous relevant Window LocalStorage Client Versus Server Primer Tutorial is shown below.
Even though we rave on a lot about serverside PHP and its $_POST method=POST (versus HTML/Javascript recipient via ? and & argument $_GET method=GET scenario) data length advantages as the recipient of an HTML form method=POST set of data that could be sizeable, weโve just realized that there is a client Javascript and window.localStorage methodology that may help alleviate the need to involve PHP (and any other serverside intervention) on occasions.
Hint: Yes, weโve raved on about this too?! Does the blog posting title give it away? Okay, yes, it should read โlocalStorageโ, but thought weโd gone past such juvenile finickiness since the Whac-A-Mole controversy of 1st December 2019 (or even The Great Tea Trolley Disaster of โ67, we daresay).
It can even use a โself-destructโ approach to the use of this โlocalStorageโ on having used it because โฆ
- the web application knows who is using it (localStorage) โฆ and on having accessed and read it โฆ
- the web application knows it (localStorage) is of no use to any other user (in this web applicationโs case, at least)
โฆ which is very pleasing for a Land Surveyor who likes to leave cow paddocks as theyโve seen them so to speak. Except itโs like having a ten tonne truck worth of data access in amongst the cow pats when having access to โlocalStorageโ (or PHP), rather than a little piddle of calf wee (wee Metcalfes know a thing or two about these things!) data access of ? and & HTML/Javascript URL arguments (or even if we were to use HTTP Cookies).
Itโs not as if we all have access to serverside language usage, though we do, because we really like PHP and MAMP and Apache/PHP/MySql web servers (and have arranged our development environment accordingly), but what if you are starting out in web development, and still want to allow for sizeable chunks of data with your web applications? Huh? Huh?! See the possibilities? Try our proof of concept CapitalCity Find Matching Country Report live run, and highlight a whole swathe of (multiple mode) dropdown option Capital Cities holding down the shift key before pressing the yellow โReportโ button. If the URL ends up as โฆ
https://rjmprogramming.com.au/HTMLCSS/wls_vs_php.html?capitals=localStorage&countries=localStorage
โฆ thatโs because the web applicationโs โฆ
function analyze() {
var purl=document.URL.split('#')[0].split('?')[0] + '?capitals=' + encodeURIComponent(document.getElementById('capitals').value) + '&countries=' + encodeURIComponent(document.getElementById('countries').value);
if (purl.length > 800) {
if (phpexists) {
document.getElementById('myform').method='POST';
document.getElementById('myform').action='./wls_vs_php.php';
} else if (window.localStorage) {
localStorage.setItem('wls_vs_php_countries', encodeURIComponent(document.getElementById('countries').value));
localStorage.setItem('wls_vs_php_capitals', encodeURIComponent(document.getElementById('capitals').value));
document.getElementById('capitals').value='localStorage';
document.getElementById('countries').value='localStorage';
location.href=document.URL.split('#')[0].split('?')[0] + '?capitals=' + encodeURIComponent(document.getElementById('capitals').value) + '&countries=' + encodeURIComponent(document.getElementById('countries').value);
return false;
}
}
return true;
}
โฆ HTML form onsubmit event logic โฆ
- discovered no PHP web application existant (via Client Pre-emptive Iframe techniques) โฆ and โฆ
- discovered (in a sanity check feeling way) that to go down the proposed HTML form method=GET approach was risking a โฆ
HTTP 414 "Request URI too long"
โฆ web browser error โฆ and that โฆ - localStorage was a known web browser piece of functionality
- back out of the default HTML form method=GET navigation setup of the web application in favour of โฆ
- storing that data into localStorage
- substituting into the URL ? and & arguments the hardcoding โlocalStorageโ (and in so doing, getting back under the HTTP 414 โRequest URI too longโ limitation, piecing together (what amounts to) โฆ
location.href=document.URL.split(โ#โ)[0].split(โ?โ)[0] + โ?capitals=localStorage&countries=localStorageโ;)
โฆ that on a recall to this same web application a โฆ - document.body onload event piece of Javascript logic checks the localStorage for its incoming Capital City Country Report data, as per โฆ
var phpexists=false;
var getcapitals=location.search.split('capitals=')[1] ? decodeURIComponent(location.search.split('capitals=')[1].split('&')[0]).replace(/\+/g,' ') : '';
var getcountries=location.search.split('countries=')[1] ? decodeURIComponent(location.search.split('countries=')[1].split('&')[0]).replace(/\+/g,' ') : '';
function checkforreport() {
var divcont='';
var dcaps, dctys, idis;
if (getcapitals == 'localStorage') {
if (window.localStorage) {
getcapitals=decodeURIComponent(localStorage.getItem('wls_vs_php_capitals')).replace(/\+/g,' ');
localStorage.removeItem('wls_vs_php_capitals');
} else {
getcapitals='';
}
}
if (getcountries == 'localStorage') {
if (window.localStorage) {
getcountries=decodeURIComponent(localStorage.getItem('wls_vs_php_countries')).replace(/\+/g,' ');
if (getcapitals.replace('localStorage','') != '' && getcountries.replace('localStorage','') != '') { document.getElementById('myh1').innerHTML+=' <font size=1>... yes, it was needed</font>'; }
localStorage.removeItem('wls_vs_php_countries');
} else {
getcountries='';
}
}
if (getcapitals != '' && getcountries != '') {
divcont='<table border=5 style="width:95%;vertical-align:top;background-color:white;"><tr style=background-color:#f0f0f0;"><th>Capital</th><th>Country</th></tr></table>';
dcaps=getcapitals.split('|');
dctys=getcountries.split('|');
for (idis=0; idis<dcaps.length; idis++) {
divcont=divcont.replace('</table>', '<tr><td>' + dcaps[idis] + '</td><td>' + dctys[idis] + '</td></tr></table>');
}
document.getElementById('dreport').innerHTML=divcont;
}
}
โฆ the localStorage.removeItem() representing that โself-destructโ nuance we were talking about before
โฆ and so as per our localStorage logic we โฆ
We may well use this methodology in future projects, and hope it has been of some little interest to you as well?!
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.
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.