how solve this appears illegal character when i click two times? - javascript

I have this function works well when i click the first time but when i click the second time receive a error in this part
eval("var " + data + "=sinvnword;");
Code:
$('a.play-video').click(function(){
var currentLocation = window.location;
var fullurl = window.location.href;
url = fullurl.split("sendx")[1];
var sinvnword = $('.question-label.active').last().text();
console.log(sinvnword);
var data =url ;
eval("var " + data + "=sinvnword;");
console.log(AXY + "GETIT");
console.log(AXY+"mor");
console.log(AXY + "muerte");
});

Rather than using eval to create dynamic variable names, simply use dynamic property names:
var data = {};
$('a.play-video').click(function(){
var currentLocation = window.location;
var fullurl = window.location.href;
var key = fullurl.split("sendx")[1];
var sinvnword = $('.question-label.active').last().text();
console.log(sinvnword);
data[key] = sinvnword;
console.log(AXY + "GETIT");
console.log(AXY+"mor");
console.log(AXY + "muerte");
});

Related

I Got A Problam In Whatsapp Sharing Using Javascript

i have a button when i click on this button then whatsapp opens and when i click in a chat and want to send massege then all things come properly but full url not come because & included in my url.
My Url is like this
www.yoururl.com?1st=1&2nd=2&3rd=2&4th=1&5th=2&6th=2&7th=2&8th=2&9th=2&10th=2&share=share&name=s
But sharing in whatsapp then comes only
www.yoururl.com?1st=1
when i remove first & Then url is comes
www.yoururl.com?1st=12nd=2
so i want to share full url with &
Here Is javascript code Code
var url1 = "?1st=" + encodeURIComponent(selectedOption1) + "&2nd=" + encodeURIComponent(selectedOption2) + "&3rd=" + encodeURIComponent(selectedOption3) + "&4th=" + encodeURIComponent(selectedOption4) + "&5th=" + encodeURIComponent(selectedOption5) + "&6th=" + encodeURIComponent(selectedOption6) + "&7th=" + encodeURIComponent(selectedOption7) + "&8th=" + encodeURIComponent(selectedOption8) + "&9th=" + encodeURIComponent(selectedOption9) + "&10th=" + encodeURIComponent(selectedOption10);
section3.style.display="none";
section4.style.display="block";
var u = "www.yoururl.com";
var input = document.getElementById("1nameInput").value;
var inputt = document.getElementById("copytxt");
var inputname = "&name=";
var share = "&share=share";
var text = u + url1 + share + inputname + input;
inputt.value = text;
var $whatsApp = $('.whatsapp a');
decorateWhatsAppLink(text, input);
function decorateWhatsAppLink(text, input) {
// Getting user input
var message = "text";
// Opening URL
var url = 'whatsapp://send?text=';
//define the message text
var textttt = 'dare take this Challenge Now ';
//encode the text
//find the link
var $whatsApp = $('.whatsapp a');
//set the href attribute on the link
$whatsApp.attr('href', url + input + textttt + text);
}
url come from text variable
please tell me how to do
use encodeURIComponent on the whole URI not only the parameter values
so that & gets encoded as well ...
foo = "www.yoururl.com?1st=1&2nd=2&3rd=2&4th=1&5th=2&6th=2&7th=2&8th=2&9th=2&10th=2&share=share&name=s"
foo_final = encodeURIComponent(foo);

Download of excel file is not working in Firefox but works in Chrome

I am trying to download an excel file on onclick event. It allow me to download excel file in chrome but not in Firefox. Not sure what is the issue. I am getting below error.
ReferenceError: event is not defined
Below is my javascript function
function hyperlinkFn(){
var htmlTbl="";
var htmlTbl1="";
var string = event.target.parentElement.name;
var tempString=[];
var temp= new Array();
for(var i=0;i<string.length;i++){
if(string[i]=="|"){
temp.push(tempString);
tempString=[];
}else{
tempString+=string[i];
}
}
userStoryModalRelease = temp[0];
userStoryModalPID = temp[1];
userStoryModalPrjName = encodeURIComponent(temp[2]);
userStoryModalTeam = encodeURIComponent(temp[3]);
userStoryAltId=encodeURIComponent(temp[4]);
userStoryModalStatus = temp[5];
userStoryModalTeam = userStoryModalTeam.replace(", ", ",");
var uri="getUserStoryDetails.htm?release=" + userStoryModalRelease + "&projectId=" + userStoryModalPID + "&projectName=" + userStoryModalPrjName +
"&team=" + userStoryModalTeam + "&alternateId=" + userStoryAltId + "&view=" + storyView;
var encode = encodeURI(uri);
window.location = encode;
}
HTML code where I am calling this function in the datatable
{
title : "Total Points",
data : function(data, type, row, meta) {
return data.totalSum+'<a name="'+ data.releaseNum +'|'+ data.projectId +'|'+ data.projectName +'|'+ data.team + '|'+ data.altId + '|total|'+'" onclick="hyperlinkFn()">'
+ '<i class="fa fa-file-excel-o font-size-15 " title="Click here to export details " aria-hidden="true"></i></a>';
},
className : "center storypoint yellow_fill pos-rel"
} ],
Change your click binding like below so that event will work:
$(document).on('click', '.classname', function(event){
var htmlTbl="";
var htmlTbl1="";
var string = event.target.parentElement.name;
var tempString=[];
var temp= new Array();
for(var i=0;i<string.length;i++){
if(string[i]=="|"){
temp.push(tempString);
tempString=[];
}else{
tempString+=string[i];
}
}
userStoryModalRelease = temp[0];
userStoryModalPID = temp[1];
userStoryModalPrjName = encodeURIComponent(temp[2]);
userStoryModalTeam = encodeURIComponent(temp[3]);
userStoryAltId=encodeURIComponent(temp[4]);
userStoryModalStatus = temp[5];
userStoryModalTeam = userStoryModalTeam.replace(", ", ",");
var uri="getUserStoryDetails.htm?release=" + userStoryModalRelease + "&projectId=" + userStoryModalPID + "&projectName=" + userStoryModalPrjName +
"&team=" + userStoryModalTeam + "&alternateId=" + userStoryAltId + "&view=" + storyView;
var encode = encodeURI(uri);
window.location = encode;
})
Note: remove onclick event from hyperlink and add class on hyperlink and replace that classname with .classname
Looks like this has already been covered here:
ReferenceError: event is not defined error in Firefox
WebKit follows IE's old behavior of using a global symbol for "event", but
Firefox doesn't. When you're using jQuery, that library normalizes the
behavior and ensures that your event handlers are passed the event
parameter.
function hyperlinkFn(){ needs to become function hyperlinkFn( event ){

Azure Account Shared Access Signiture

I am trying to construct an Account level Shared Access Signiture so my client can access all containers in a storage account. I am following these docs Account SAS. It seems straight forward enough but I keep getting the following error message:
"Signature did not match. String to sign used was accountname\nrl\nb\nsc\n\n2016-10-09\n\n\n2015-04-05\n".
My parameters are identical so I suspect it has something to do with how I am hashing the String to Sign. Below is how I construct the token.
var crypto = require('crypto');
var accountName = 'accountname';
var accountKey = 'tH37FTlG3TUT86caMrt2y5kOzof8nFqqA6spzg6r7HPRojE1zDiLJD/xE4oLFDh4RNqAmymvlV7fm8W4SF8cJg==';
var signedPermissions = "sp=rl";
var signedServcies = "ss=b";
var signedResourceType = "srt=sc";
var signedExpiry = "se=2016-10-09";
var signedVersion = "sv=2015-04-05";
var stringToSign = accountName + "\n" + signedPermissions + "\n" + signedServcies + "\n" + signedResourceType + "\n" + signedExpiry + "\n" + signedVersion + "\n";
var hmacsha256 = crypto.createHmac('sha256', accountKey).update(stringToSign).digest('base64');
var token = signedPermissions + "&" + signedServcies + "&" + signedResourceType + "&" + signedExpiry + "&" + signedVersion + "&sig=" + hmacsha256;
I have tried using crypto-js as well but to no avail. The final URL used to access a blob in a container is...
"https://accountname.blob.core.windows.net/containername/blobName?srt=sc&se=2016-10-09&api-version=2015-04-05&sp=rl&ss=b&sv=2015-04-05&sig=IFD2wyfRAsHGU5IFg3RbwSJW6tRE0m0%2FxgAYvJ%2FmnEk%3D"
I have been trying for days and really would appreciate knowing what I'm doing wrong. Thanks.
Benzene, for stringToSign, the value should NOT has the parameter name?
var signedPermissions = "rl";
var signedServcies = "b";
var signedResourceType = "sc";
var signedExpiry = "2016-10-09";
var signedVersion = "2015-04-05";
Please try the following (code shamelessly taken from Azure Storage Node.js library):
var hmacsha256 = crypto.createHmac('sha256', new Buffer(accountKey, 'base64')).update(stringToSign, 'utf-8').digest('base64');

How to Clear then Append URL with JavaScript

I am trying to reload a page after a few seconds and append the URL with a variable containing new Lat Long coordinates. Consider the code snippet below that works with Leaflet:
var latlng = getQueryVariable("latlng");
if(latlng){
console.log(latlng); //working
}
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("?");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}
alert('Query Variable ' + variable + ' not found');
}
function onMapClick(e) {//Coordinate pop up
popup.setLatLng(e.latlng)
.setContent("Coordinates clicked are: " + e.latlng.toString())
.openOn(map);
var centerPoint = map.getSize().divideBy(2),
targetPoint = centerPoint.subtract([1500, 0]),
targetLatLng = map.containerPointToLatLng(centerPoint), //retrieve new lat longs
loadLatlng = "?latlng="+targetLatLng.lat+","+targetLatLng.lng;
setTimeout(function(){
//And herein lies the problem - the URL is being concatenated ??
window.location.href = window.location.href + loadLatlng;
window.location.href.reload(1);
}, 5000);
}
Does anyone know how to clear and then append the URL?
Thanks.
Build the url using the parts
window.location.href = [location.protocol, '//', location.host, location.pathname, loadLatlng].join("");
Same thing as
window.location.href = location.protocol + '//' + location.host + location.pathname + loadLatlng;
You could also do it a dirty way with splitting the current url on the ?
window.location.href = window.location.href.split("?")[0] + loadLatlng;

Getting group value of element ID with Regex/Javascript

I have a DIV with element id; e.g. "bgjhkn2n2-20". I'm trying to get the regex right so I can load reports dynamically into div's based on id.
console.log(elemID) prints the bgjhkn2n2-20 as expected. It's not printing the # that normally prefixes element Id. console.log(repDBID[0]) prints the full element ID; but I can not get firebug to print the groups I get from a similar test in a regextester with console.log(repDBID[0]). If I append an index number to the match statement, it returns null.
Help?
var baseURL = window.location.protocol + "//" + window.location.hostname + "/db/";
var genREP = "?a=API_GenResultsTable&qid=";
$('#tab1 div').each(function (e){
var elemID = this.getAttribute('id');
console.log(elemID);
var pattern=/([a-z0-9]{9})-([1-9]{1}[0-9]*)/g
var repDBID = elemID.match(pattern); //get dbid
console.log(repDBID[0]);
var repID = elemID.match(pattern)[2]; //get qid
//console.log(repID);
//$(this).load(baseURL+repDBID+genREP+repID);
$('#repTabs').tab(); //initialize tabs
});
Remove the g from your regex and it should work just fine:
var baseURL = window.location.protocol + "//" + window.location.hostname + "/db/";
var genREP = "?a=API_GenResultsTable&qid=";
$('#tab1 div').each(function(e) { // You might need `#tab1 > div`
var parts = this.id.match(/([a-z0-9]{9})-([1-9]{1}[0-9]*)/);
var repDBID = parts[1];
var repID = parts[2];
$(this).load(baseURL + repDBID + genREP + repID);
$('#repTabs').tab();
});
Here's what I mean:
> id.match(/([a-z0-9]{9})-([1-9]{1}[0-9]*)/g);
["bgjhkn2n2-20"]
> id.match(/([a-z0-9]{9})-([1-9]{1}[0-9]*)/);
["bgjhkn2n2-20", "bgjhkn2n2", "20"]

Categories