{"id":45443,"date":"2019-06-27T03:01:23","date_gmt":"2019-06-26T17:01:23","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=45443"},"modified":"2019-06-27T19:43:33","modified_gmt":"2019-06-27T09:43:33","slug":"gmail-url-linker-simulation-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/gmail-url-linker-simulation-primer-tutorial\/","title":{"rendered":"Gmail URL Linker Simulation Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/gmail_linker_simulation.html\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Gmail URL Linker Simulation Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/gmail_linker_simulation.jpg\" title=\"Gmail URL Linker Simulation Primer Tutorial\"  style=\"float:left;\"   \/><\/a><p class=\"wp-caption-text\">Gmail URL Linker Simulation Primer Tutorial<\/p><\/div>\n<p>We take a small sidestep away from yesterday&#8217;s <a target=_blank href='https:\/\/www.rjmprogramming.com.au\/ITblog\/overlay-iframe-remembering-textarea-client-sharing-tutorial\/' title='Overlay Iframe Remembering Textarea Client Sharing Tutorial '>Overlay Iframe Remembering Textarea Client Sharing Tutorial <\/a> today, though today&#8217;s content becomes relevant to it, and <a target=_blank title='?' href='https:\/\/forums.theregister.co.uk\/forum\/all\/2007\/11\/08\/top_movie_quotes\/#c_93333'>&#8220;we will return&#8221;<\/a>.<\/p>\n<p>So, can we say we are admirers of the webmail product <a target=_blank title='Gmail' href='https:\/\/gmail.com'>Gmail<\/a> (by Google), in the way you can write in the body of your email some text that includes an absolute URL (not in any HTML, just as text), and the email recipient sees that URL text linked?  Of course, in a serverside language like PHP we&#8217;d simulate that via a function like <a target=_blank title='PHP preg_replace' href='https:\/\/www.php.net\/manual\/en\/function.preg-replace.php'>preg_replace<\/a> <font size=1>(the &#8220;pregs&#8221;, in PHP, all involving such &#8220;regex&#8221; fun!)<\/font>, but we want to do something similar in &#8220;clientland&#8221; Javascript <font size=1>(and we promise we are not masochists &#8230; <a target=_blank title='?' href='https:\/\/www.roalddahl.com\/roald-dahl\/characters\/beasts\/the-enormous-crocodile'>honest?!?<\/a>)<\/font>.  Can we separate <i>textual use of HTTP prefixed &#8220;words&#8221;<\/i> as distinct from <i>HTML usage of HTTP prefixed references<\/i>?  We think so, as we think we can say the &#8220;regex&#8221;y [hH][tT][tT][pP] would be prefaced by one of &gt; or &#8216; or &#8221; if it was a <i>HTML usage of HTTP prefixed references<\/i> scenario.  Obversely <font size=1>(in &#8220;obverse land&#8221;)<\/font> the &#8220;regex&#8221;y [hH][tT][tT][pP] would be prefaced by one of ^ (ie. start of line) or \\n (ie. line feed) or \\s (ie. a space) if you are in a <i>textual use of HTTP prefixed &#8220;words&#8221;<\/i> scenario.  Given that, what is the Javascript for this idea?<\/p>\n<p><code><br \/>\n&lt;script type='text\/javascript'&gt;<br \/>\n\/\/ Thanks to <a target=_blank title='https:\/\/stackoverflow.com\/questions\/41306338\/match-any-group-of-characters-before-a-line-break-sign' href='https:\/\/stackoverflow.com\/questions\/41306338\/match-any-group-of-characters-before-a-line-break-sign'>https:\/\/stackoverflow.com\/questions\/41306338\/match-any-group-of-characters-before-a-line-break-sign<\/a><br \/>\n\/\/ Thanks to <a target=_blank title='https:\/\/stackoverflow.com\/questions\/494035\/how-do-you-use-a-variable-in-a-regular-expression' href='https:\/\/stackoverflow.com\/questions\/494035\/how-do-you-use-a-variable-in-a-regular-expression'>https:\/\/stackoverflow.com\/questions\/494035\/how-do-you-use-a-variable-in-a-regular-expression<\/a><br \/>\n<br \/>\nvar gmail_linker_prefix=\" &lt;a target=_blank class='gmail_style_link' title='Gmail style link' href='\";<br \/>\nvar gmail_linker_middle=\"'&gt;\";<br \/>\nvar gmail_linker_suffix=\"&lt;\/a&gt; \";<br \/>\nvar lastlinks=[];<br \/>\n<br \/>\n\/\/ RegExp.quote = function(str) {<br \/>\n\/\/     return str.replace(\/([.?*+^$[\\]\\\\(){}|-])\/g, \"\\\\$1\");<br \/>\n\/\/ };<br \/>\n<br \/>\nfunction futuremore(inw) {<br \/>\n  var parts=inw.split(gmail_linker_prefix), lastlink='';<br \/>\n  lastlinks=[];<br \/>\n  for (var ij=1; ij&lt;parts.length; ij++) {<br \/>\n    if (parts[ij].indexOf(gmail_linker_middle) != -1 && parts[ij].indexOf(gmail_linker_suffix) != -1) {<br \/>\n      if (lastlink != parts[ij].split(gmail_linker_middle)[0]) {<br \/>\n        lastlink=parts[ij].split(gmail_linker_middle)[0];<br \/>\n        lastlinks.push(lastlink);<br \/>\n        \/\/alert(lastlink);<br \/>\n      }<br \/>\n    }<br \/>\n  }<br \/>\n  return inw;<br \/>\n}<br \/>\n<br \/>\nfunction tostr(what) {<br \/>\n  return gmail_linker_prefix + what + gmail_linker_middle + what + gmail_linker_suffix;<br \/>\n}<br \/>\n<br \/>\nfunction preg_replace_http(ions) {<br \/>\n  return futuremore(ions.replace(\/\\ [hH][tT][tT][pP]([^\\s]+)\/g, tostr(\"\\$&\")).replace(\/^[hH][tT][tT][pP]([^\\n]+)\/g, tostr(\"\\$&\") + String.fromCharCode(10)).replace(\/\\n[hH][tT][tT][pP]([^\\n]+)\/g, String.fromCharCode(10) + tostr(\"\\$&\") + \"\").replace(\/\\'\\n[hH][tT][tT][pP]\/g, \"'http\").replace(\/\\\"\\n[hH][tT][tT][pP]\/g, '\"http').replace(\/\\&gt;\\n[hH][tT][tT][pP]\/g, '&gt;http').replace(\/\\ [hH][tT][tT][pP]\/g, \"http\"));<br \/>\n}<br \/>\n<br \/>\n&lt;\/script&gt;<br \/>\n<\/code> <\/p>\n<p> &#8230; where <i>preg_replace_http([yourGmailBodySimulatedTextGoesHere])<\/i> is the Javascript call we use in the HTML and Javascript <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/gmail_linker_simulation.html_GETME\">gmail_linker_simulation.html<\/a>&#8216;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/gmail_linker_simulation.html\">live run<\/a> (new window) link, or in an HTML iframe as below &#8230;<\/p>\n<p><iframe style=\"width:100%;height:600px;\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/gmail_linker_simulation.html\"><\/iframe><\/p>\n<p>See those links (thanks heaps) above for advice regarding Javascript <a target=_blank title='Javascript string replace function information from w3schools' href='http:\/\/www.w3schools.com\/jsref\/jsref_replace.asp'><i>replace<\/i><\/a> function&#8217;s special &#8220;place&#8221; for &#8220;$&#038;&#8221; and &#8220;$1&#8221; (type syntax) in &#8220;the pantheon of replacement&#8221; and &#8220;temple of <a target=_blank title='?' href='https:\/\/www.google.com\/search?q=reg+the+bill&#038;rlz=1C5CHFA_enAU832AU832&#038;source=lnms&#038;sa=X&#038;ved=0ahUKEwiYt-noi4bjAhXEb30KHakPBbkQ_AUICSgA&#038;biw=1440&#038;bih=746&#038;dpr=2'>reg<\/a><a target=_blank title='?' href='https:\/\/www.google.com\/search?rlz=1C5CHFA_enAU832AU832&#038;q=The+Bill&#038;stick=H4sIAAAAAAAAAONgFuLUz9U3MLcoSC9WAjMNc8qycrSEHJNL8otC8kPCHPNSfPPLMlOLF7FyhGSkKjhl5uTsYGUEAG3pYNU6AAAA&#038;sa=X&#038;ved=2ahUKEwjcs5Pmi4bjAhVNWysKHdLLDhwQxA0wIHoECBAQBQ&#038;cshid=1561515852594497&#038;biw=1440&#038;bih=746'>ex<\/a>&#8220;.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d45443' onclick='var dv=document.getElementById(\"d45443\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/gmail\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d45443' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>We take a small sidestep away from yesterday&#8217;s Overlay Iframe Remembering Textarea Client Sharing Tutorial today, though today&#8217;s content becomes relevant to it, and &#8220;we will return&#8221;. So, can we say we are admirers of the webmail product Gmail (by &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/gmail-url-linker-simulation-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,14,37],"tags":[52,155,380,503,576,2828,652,1807,997,2994,2589,1254,1262,1319,1345,1417],"class_list":["post-45443","post","type-post","status-publish","format-standard","hentry","category-elearning","category-event-driven-programming","category-tutorials","tag-absolute-url","tag-body","tag-email","tag-gmail","tag-html","tag-hyperlink","tag-javascript","tag-link","tag-programming","tag-simulate","tag-simulation","tag-text","tag-textarea","tag-tutorial","tag-url","tag-webmail"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/45443"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=45443"}],"version-history":[{"count":1,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/45443\/revisions"}],"predecessor-version":[{"id":45444,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/45443\/revisions\/45444"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=45443"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=45443"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=45443"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}