I would like to know email ids in thymleaf template to mailto link
eg : hello#gmail.com to
It should use regex for finding email IDs.
I have tried with thymleaf inline javascript but unfortuantely not working in outlook.
<script>
/*<![CDATA[*/
function formatEmails(){
var content=document.getElementById('content').innerHTML;
var regex = /\S+#\S+\.\S+/g
var matches = [];
var match = regex.exec(content);
var formatedContent=content;
while (match != null) {
if(matches.indexOf(match[0]) === -1)matches.push(match[0]);
match = regex.exec(content);
}
matches.forEach(function(email,index){
formatedContent=formatedContent.split(email).join(''+email+'')
});
document.getElementById('content').innerHTML=formatedContent;
}
/*]]>*/
</script>
If there is no direct way to do this, how to make it?
Thanks in advance.
Related
I am trying to get value in the editor but undefined incoming?
#Html.Editor("ProductName")
Javascript code...
$(document).ready(function () {
$(".click").click(function () {
var proName = $("ProductName").val();
var code = "<tr><td><input type='checkbox' name = 'chk'/></td><td>" + proName +"</td></tr>"
}
}
In jQuery, if you want to select an element by its Id then you should specify # sign before Id.
var proName = $("#ProductName").val();
For more information please follow this.
I have created a Feedback form and want to open it from and share it across multiple spreadsheets. I have used a revised version of the code in the following post Single Google Form for multiple Sheets.
The form opens as expected as an IFRAME but does not allow me (or any user) to populate the fields and create a response. What am I missing?
function onOpen() {
var ui = SpreadsheetApp.getUi();
// Or DocumentApp or FormApp.
ui.createMenu('Data Architecture')
.addItem('Create File Note', 'menuItem1')
.addSeparator()
.addSubMenu(ui.createMenu('Feedback & Actions')
.addItem('Provide Feedback', 'provideFeedback')
.addItem('Create and Action', 'createAction'))
.addToUi();
}
function provideFeedback() {
var documentName = SpreadsheetApp.getActive().getName();
var dataentityName = SpreadsheetApp.getActiveRange().getCell(1, 1).getDisplayValue();
launchForm();
}
function createAction() {
var documentName = SpreadsheetApp.getActive().getName()
var documentID = SpreadsheetApp.getActive().getId()
var dataentityName = SpreadsheetApp.getActiveRange().getCell(1, 1).getDisplayValue()
launchForm();
}
function launchForm(){
var formID='1pmH3AWiMUczat5uIaZ5zaT--cmDjq9v3W9pePPjwGF0';
var form = FormApp.openById(formID);
var formURL = form.getPublishedUrl();
var response = UrlFetchApp.fetch(formURL);
var formHtml = response.getContentText();
var htmlApp = HtmlService
.createHtmlOutput(formHtml)
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setTitle('Feedback and action form')
.setWidth(800)
.setHeight(800);
SpreadsheetApp.getActiveSpreadsheet().show(htmlApp);
}
Instead of accessing the web page and generating the HTML content and serve it again, you can use iframe tag with src to your URL to do it for you.
function launchForm(){
var formID='1pmH3AWiMUczat5uIaZ5zaT--cmDjq9v3W9pePPjwGF0';
var form = FormApp.openById(formID);
var formURL = form.getPublishedUrl()+ "?embedded=true"
var htmlApp = HtmlService
.createHtmlOutput('<iframe src="'+formURL+'" width="500" height="400" frameborder="0" marginheight="0" marginwidth="0"> </iframe>')
.setTitle('Feedback and action form')
.setWidth(400)
.setHeight(400);
SpreadsheetApp.getActiveSpreadsheet().show(htmlApp);
}
To have pre-filled form to be used in your script:
1) Get a prefilled Form, by following the steps here
2) For a form like this:
the prefilled url will look like this:
var formURL = "https://docs.google.com/forms/d/e/{Publish ID}/viewform?
usp=pp_url&
entry.1739076204=Jack+Brown&
entry.1869878870=2017-05-12&
entry.799903038=Incorrect&
entry.1996064114=I+am+the+best&
entry.607023772=Select+Me"
I have separated out the individual options so that it is easier to compare with an entry in the form. Now to modify the entry all you have to do is modify the value after '=' sign for each entry. So to change the name you would do:
var name = "Chuck Norris"
entry.1739076204='+name+'
Similarly, you can modify each enter by modifying the URL. The below code modifies the entry for a specific form I have hosted. You will have to modify if as per your needs
function launchForm(){
var publishedURl = "https://docs.google.com/forms/d/e/1FAIpQLSdsHM53jTWJ0Eqn8VSxE5bWHjnD9KXsVBrqLsBwtyJIIsjpnA/viewform"
var name = "Chuck Not Norris"
var dt = Utilities.formatDate(new Date(), "GMT-05:00", "yyyy-MM-dd")
var options1 = ["Correct","Incorrect"]
var options2 = "Chuck Norris is google Apps Scripts"
var options3 = ["Select Me","Don't select me"]
var preEditUrl = publishedURl + '?usp=pp_url&entry.1739076204='+name
+'&entry.1869878870='+dt
+'&entry.799903038='+options1[0]
+'&entry.1996064114='+options2
+'&entry.607023772='+options3[0]
var htmlApp = HtmlService
.createHtmlOutput('<iframe src="'+preEditUrl+'" width="500" height="400" frameborder="0" marginheight="0" marginwidth="0"> </iframe>')
.setTitle('Feedback and action form')
.setWidth(400)
.setHeight(400);
SpreadsheetApp.getActiveSpreadsheet().show(htmlApp);
}
Hopefully, this will get you started in the right direction.
I want to track the conversion for links in adwords; For this i have the classic code that looks like this(don't worry about values for conversion_id and conversion_label):
<!-- Google Code for Joc Sloturi2 Conversion Page
In your html page, add the snippet and call
goog_report_conversion when someone clicks on the
chosen link or button. -->
<script type="text/javascript">
/* <![CDATA[ */
goog_snippet_vars = function() {
var w = window;
w.google_conversion_id = xxxxxxx;
w.google_conversion_label = "dsadsadsadsadadsa";
w.google_conversion_value = dsadasda;
w.google_conversion_currency = "RON";
w.google_remarketing_only = false;
}
// DO NOT CHANGE THE CODE BELOW.
goog_report_conversion = function(url) {
goog_snippet_vars();
window.google_conversion_format = "3";
var opt = new Object();
opt.onload_callback = function() {
if (typeof(url) != 'undefined') {
window.location = url;
window.open(url, '_blank')
}
}
var conv_handler = window['google_trackConversion'];
if (typeof(conv_handler) == 'function') {
conv_handler(opt);
}
}
/* ]]> */
</script>
<script type="text/javascript"
src="//www.googleadservices.com/pagead/conversion_async.js">
</script>
After that the outbound links are looking like this
Link text whatever
My problem with this is that when I click on the link it opens the link in a new tab and also in the same tab (basically it opens the link twice); Is there a way to only open the link in a new tab in the browser and also track the conversion for it?
I know this is a bit old, but I found a solution. Remove
window.location = url;
I have a button that opens up a dialog containing another html file. What I would like to be able to do is pass a variable to the dialog. This is what I have.
var html = "";
var PLAN_ID = '1234';
html += "<div>"
html += 'Final'
html += "</div>"
The PLAN_ID variable is the one that I wish to push to the formFinal.html. I can populate a hidden text input on the dialog with the following code.
$(document).on('pageshow', '#FinalPostPage', function(e) {
var page = $(this);
var query = page.data("url").split("?")[1];
var planid = query.split("=")[1];
$("input[name=Title]",this).val(planid);
})
I can use this but the variable doesn't populate until after the formFinal.html page loads it seems. I need the variable to be used while the page develops. Hope this makes sense.
You could use localStorage to transfer data from this page to the other page.
When you're creating the button, add the PLAN_ID variable as a data-* attribute to the a and also create an id/class for it :
var html = "";
var PLAN_ID = '1234';
html += "<div>"
html += 'Final'
html += "</div>"
Write a click event for the button click :
$(document).on("click", '#dialog-send' ,function(e) {
//prevent default action. we dont want it to redirect. Just yet.
e.preventDefault();
//set item in localStorage.
localStorage["plan_id"] = $(this).data("planid");
//then use changePage to redirect
$.mobile.changePage(this.href, {transition: 'pop', role: 'dialog'});
});
In your pageshow event,
$(document).on('pageshow', '#FinalPostPage', function(e) {
var page = $(this);
//var query = page.data("url").split("?")[1];
//get plan id from localStorage
var planid = localStorage["plan_id"];
$("input[name=Title]",this).val(planid);
});
Hope this helps.
I am trying to generate an url for an MVC 3 action within javascript environment (in a cshtml file).
<script type="text/javascript">
...
var src = "#Url.Action("GetProductImage", new { productId = Model.Product.Id, pos = 1, size = 0 })";
$(document.createElement("img")).attr("src", src);
...
</script>
Now this works almost fine, my problem is that the querystring is being escaped.
Instead of:
"/Products/GetProductImage?productId=1&pos=0&size=0"
it generates:
"/Products/GetProductImage?productId=1&pos=0&size=0"
so my action does not get called.
Now I know I can make my own custom Url helper function, but I was wondering if I can use this or some other built in helper to get the unescaped URL?
Thanks in advance, G.
<script type="text/javascript">
var src = "#Html.Raw(Url.Action("GetProductImage", new { productId = Model.Product.Id, pos = 1, size = 0 }))";
$(document.createElement("img")).attr("src", src);
</script>
var src = "#Html.Raw(Url.Action("GetProductImage", new { productId = Model.Product.Id, pos = 1, size = 0 }))";
Url.Action worked for me not HtmlUrl.Action
Enjoy!