startupdate In both "what-I-get" and "what-I-want-to-get" below, the word data should really be details, so I am not even getting what I thought and do not understand the function downloadUrl at all, apparently. Am I using the wrong utility function? Any clarification would be greatly appreciated.
endupdate
When I submit the form below (entering 'Brian'), the result I see in the browser address is as follows.
http://localhost:8092/click?data=Brian#
But I want it to be something like the following, so that my python app processes it. (I am not sure about this exactly, but hopefully you know what I mean.)
http://localhost:8092/details.txt?Action=add&data=Brian#
Can you tell me how to get the desired result?
My python contains the following.
app = webapp2.WSGIApplication(
[('/', MainPage),
('/details.txt', Details),
('/comment', DetailsLog)],
debug=True)
My javascript contains the following script for processing a form.
var iwform = '<br />'
+ '<form onsubmit="process(this); return false" action="#">'
+ ' <input type="text" name="data" id="idinput" size="31" maxlength="31" tabindex="1"/>'
+ ' <input type="submit" value="Submit" tabindex="4"/>'
+ '<\/form>';
function process(form) {
var details = escape(form.data.value);
var url = "details.txt?Action=add&details="+details;
downloadUrl(url, function(doc) { });
map.closeInfoWindow();
alert("Your information has been processed.");
}
The function downloadUrl() is from photomunchers.com and is designed (I believe) to replace a deprecated google map's function GDownloadUrl().
My problem was that in using the function downloadUrl() I inadvertently forgot to load its src in some of my templates.
Thanks,
Related
I'm trying to implement google ads conversion on my website and as per the google team, I added the tags they gave yet the conversion is not showing up properly.
After getting in touch with one of the team members, he told me to correct the code:
So far My code:
I m passing an email value through the URL to the 'Thank-you' page.
I m echoing the value inside a hidden input tag and calling it back using ID in javascript
I can get the value from the input and print it in the console.
<input type="hidden" id="email_for_ads" value="some#email.com">
<script>
var email_for_ads = $("#email_for_ads").val();
var enhanced_conversion_data = {
"email": email_for_ads
};
console.log(email_for_ads);
</script>
I can see the email id in the console, and I'm sure the value is being fetched.
But he said it should be like below upon inspect :
<input type="hidden" id="email_for_ads" value="some#email.com">
<script>
var email_for_ads = $("#email_for_ads").val();
var enhanced_conversion_data = {
"email": "some#email.com"
};
console.log("some#email.com");
</script>
I even tried the below code too
var baseUrl = (window.location).href; // You can also use document.URL
var email_for_ads = baseUrl.substring(baseUrl.lastIndexOf('=') + 1);
//var email_for_ads = $("#email_for_ads").val();
var enhanced_conversion_data = {
"email": email_for_ads
};
console.log(email_for_ads);
yet the same output. I can see the value in the console but on inspect. But he insists that it is that way and could be able to see the email value directly in inspecting itself.
Can someone understand, whether this is possible, if so, how can i do it.
It's possible, but very very weird, and I'd highly recommend against it - it doesn't provide any benefits except, I guess, when debugging, but when debugging it'd be easier to just retrieve the input value.
If you wanted the input value to be printed directly in the <script> tag, you'd have to create the script tag dynamically, either with document.createElement('script') or document.write.
For that to be possible, you'd need another script tag to create the dynamic script tag.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="hidden" id="email_for_ads" value="some#email.com">
<script>
// remove this script tag
document.currentScript.remove();
// append new script tag, with the input value directly in the source code
const email_for_ads_first = $("#email_for_ads").val();
document.write(`
<script>
var email_for_ads = $("#email_for_ads").val();
var enhanced_conversion_data = {
"email": "${email_for_ads_first}"
};
console.log("${email_for_ads_first}");
// log this script tag contents, so you can see what's in it:
console.log(document.currentScript.textContent);
<\/script>
`);
</script>
There's no good reason do this. Please don't.
You may need a server-side rendering technology to generate your email value into your HTML and scripts.
You can consider starting a service in nodejs, get the email value in the request,and in the responseļ¼return the email with your html and scripts.
I am trying to make it so that my audio player can pull MP3's off of other links and stream them through jPlayer.
var solution="html,flash";var mac=navigator.userAgent.indexOf("Mac OS X");var w51=navigator.userAgent.indexOf("Windows NT 5.1");var ie8=navigator.userAgent.indexOf("MSIE 8.0");var firefox=navigator.userAgent.indexOf("Firefox");var chrome=navigator.userAgent.indexOf("Chrome");if(mac!=-1&&firefox!=-1||w51!=-1&&firefox!=-1||ie8!=-1)
{solution="flash,html";}var resource={};if(chrome!=-1&&"mp3"=="mp3"){resource["m4a"]="somemusicfile.mp3";}else{resource["mp3"]="somemusicfile.mp3";}
$("#podbean_palyer").jPlayer({ready:function(event){$(this).jPlayer("setMedia",resource);},play:function(){removeMask();},loadedmetadata:function(){removeMask();},error:function(event){switch(event.jPlayer.error.type){case $.jPlayer.error.URL:removeMask();break;case $.jPlayer.error.NO_SOLUTION:removeMask();break;}},swfPath:"",supplied:"m4a,oga,mp3",solution:solution,cssSelectorAncestor:"#pd_container",wmode:"window",smoothPlayBar:true,keyEnabled:true,});
My code is beyond messy and I am sooo sorry for that how ever what I am trying to achieve should be able to be solved despite how messy my code is.
I want to be able to make it so that when a user types in the url www.example.com/embed-player/?mp3=SomeNewSong.mp3 it will replace the portion in my code which currently contains somemusicfile.mp3 for both of the locations it's currently in.
ok... if I got it. your code is a little confussing but I hope this can help you
you want to get song name from url and then put it in your resource variable, if that is right:
Use this:
function getURLParameter(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null
}
and thens something like this:
//using this url www.example.com/embed-player/?mp3=SomeNewSong.mp3
//parameter is mp3 (query string)
resource["m4a"] = getURLParameter('mp3') || "somemusicfile.mp3";
I have an Spring Server with HTML pages with Thymeleaf Engine and I am using jQuery for making a getJSON:
When my server is redirecting to that URL localhost:8080/redirect_admin/ where is the the next peace of code:
<table>
<tr>
<td>
<input type="text" class="add_youtube_link" th:id="${id_local}" />
<input type="button" id="upload_youtube_links" onclick="add_youtube_link()" value="Add new Youtube Link"/>
</td>
</tr>
</table>
Where I can add a link to add in my server. Well, when I click on onclick the next Javascript function will run:
function add_youtube_link()
{
var url2 = "add_youtube_link/"+$(".add_youtube_link").attr('id')+"/"+$(".add_youtube_link").val().replace(/\//g,"_");
alert(url2);
$.getJSON(url2, function (data) {
// window.location = "redirect_media/"+$(".add_youtube_link").attr('id');
});
}
So, the alert function is showing correctly the new URL: add_youtube_link/1/ZyDO4FUVxXk untill this point all is OK.
But, if I take a look in the Network Log on Chrome, the URL called is:
GET http://localhost:8080/redirect_media/add_youtube_link/1/ZyDO4FUVxXk 404 (Not Found) .
So, the problem is that the previous URL redirect_admin/ is adding automatically in the new URL. Anyone knows how to solve it?
Thank you
Its always a good idea to use a base url in your code, so you don't face issues like this:
var baseUrl = location.protocol + "//" + location.hostname + (location.port && ":" + location.port) + "/";
Then include that base url with any url
var url2 = baseUrl + "add_youtube_link/"+$(".add_youtube_link").attr('id')+"/"+$(".add_youtube_link").val().replace(/\//g,"_");
Usually this kind of error happens when your physical script file's address is different from your html page.The solution is that we always pass the partial address from the context where the function is called and in this case is your html page.
I am sending an email via javascript. In mail.parameter.text property I need to send the hyperlink. In the code below I am hardcoding the url whick looks very lengthy and also I need to add the /dashboard at the end of the url. Any idea on how to shorten the url?
var parent = space.getParent();
var siteGroup = "GROUP_EMAIL_CONTRIBUTORS";
var mail = actions.create("mail");
mail.parameters.to_many = siteGroup;
mail.parameters.subject="New Site Created in Community"
mail.parameters.text=" A new site called " + document.properties.name +"is created.Click http://pc1:8080/share/page/site/"+document.properties.name+"/dashboard"+" to join the site";
//execute action against a document
mail.execute(document);
Sorry if this is a basic question I dont know javascript. This is my entire script and I am not using any html tags in between.
You can change it to something like this, for example:
mail.parameters.text="Click <a href='http://pc1:8080/share/page/site/" + document.properties.name + "/dashboard'>here</a>";
Your link will appear as "here" and nevertheless lead to the URL you specified. Is that what you mean by "shorten the url"?
Please try now.
var url = "Click http://pc1:8080/share/page/site/" + document.properties.name + "/dashboard" + " to join the site";
ail.parameters.text = url;
I want to make registration form and write the data into data.txt using ActiveXObject.
What I write is
<script type="text/javascript">
function WriteFile()
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fh = fso.CreateTextFile("E:\\Test.txt", true);
x=document.getElementById("name").value;
y=document.getElementById("password").value;
fh.WriteLine(x+"#"+y);
fh.Close();
}
</script>
<BODY>
<form>
<input type="text" id="name"/>
<input type="text" id="password"/>
<input type="button" value="Sign Up" id="write" onclick="WriteFile()"/>
</form>
</BODY>
When I tried that way, every time I click Sign Up button, the new data override the previous data. I tried to use fh.AppendLine(x + "#" + y) but it didn't work.
Could anyone help me how to add data, not override data?
Disclaimer You should never use those functions. They only work in IE and are horrible.
I think your problem stems from using CreateTextFile. You should instead be using OpenTextFile with the second parameter set to 8. That will allow for appending.
I've done stuff like this a long time ago... (when I was using windows) I think it is because you're replacing the file with a new file with CreateTextFile so if the file already exists you'll need to do this:
function AppendLine()
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fh = fso.OpenTextFile("E:\\Training Asslab\\Advance\\Write to File\\Test.txt", 8, True);
x=document.getElementById("name").value;
y=document.getElementById("password").value;
fh.WriteLine(x+"#"+y);
fh.Close();
}
CreateTextFile overrwrites the current file, I think.
You should use FileExists to check its presence before creating it.
If it does exist you can use OpenTextFile.
Here's the relevant documentation
Use OpenTextFile method with create flag and ForAppending mode instead of CreateTextFile.
However, do understand, that you're not only limiting yourself to very old IE version and inside trusted zone, but you're also leaving files on user's local drives, not on your server. Because of that you can't do anything with this "registration data".