Sorry we could not fetch the image - javascript

I am facing one issue "Sorry we could not fetch the image" when I am clicking on pin it button:
below is the parameters I am passing
I am not getting what the this is missing :
1) ?url=
2) &media=
3) &description
This is the link which is creating in dailogbox :
http://www.pinterest.com/pin/create/button/?url=https://www.elivatefitness.com/lifestrength-ion-wristbands&media=https://www.elivatefitness.com/medias/LFE102-PureSeriesBlackGray.jpg-Default-WorkingFormat-479Wx479H?context=bWFzdGVyfHJvb3R8MTUxOTV8aW1hZ2UvanBlZ3xoNTUvaDFhLzg3OTk2MTg2NjI0MzAuanBnfDViZmIwMzM4ZTQ0NGQyYjQ1NWY2YmJkZTAxMjdjYjhmNjA3ZDk3ZDUwYTI2M2FmNzA1YjBlMTQyNDAyNzI1MTE&description=Combining%20comfort%20and%20improved%20performance%20the%20LifeStrength%20Ion%20Wellness%20Wristbands%20play%20an%20important%20part%20in%20boosting%20energy%20and%20fighting%20the%20negative%20effects%20of%20the%20environment%20around%20us%20to%20bring%20better%20health,%20relieve%20painful%20joints%20and%20encourage%20a%20deeper%20and%20more%20restful%20sleep.%20LifeStrength%20Ion%20Wellness%20Wristbands%20uses%20a%20proven%20method%20that%20combines%207%20natural%20minerals%20and%20gemstones%20into%20a%20slim%20Far-Infared%20infused%20silicon%20wristband%20you%20can%20wear%2024%20hours%20a%20day,%207%20days%20a%20week.%20Together%20the%20powerful%20mixture%20creates%20a%20unique%20band%20that%20emits%20more%20health-producing%20negative%20ions%20into%20your%20environment%20which%20in%20turn%20increases%20the%20flow%20of%20oxygen%20to%20the%20brain%20resulting%20in%20greater%20energy,%20alertness%20and%20an%20overall%20feeling%20of%20well-being.
Please help me out.
function pinIt()
{
var mediaURL = location.protocol + "//" + location.host
+ '${imgURL}' + "&description=" + "${description}";
window.open("//pinterest.com/pin/create/button/?url="+ document.URL + "&media=" + mediaURL,"",'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');
}

Related

JS hide email function not working

I took the code below from a wider document, and tried to include it between 2 script tags, but for some reason it's not working (nothing happens).
Do I need to add some document ready syntax or something like this?
Thanks,
<script>
function sendAnnotatedMailTo(name, company, domain, subject, body) {
locationstring = 'mai' + 'lto:' + name + '#' + company + '.' + domain + "?subject=" + escape(subject) + "&body=" + escape(body);
window.location.replace(locationstring);
}
</script>
You only defined a function but didn't call it.
You have to call your function like this:
Send mail
This will open your mail client and prepare an email to name#democompany.domain.tld with the subject "Subject of mail" and the bodytext "Body of mail".
Btw: You shouldn't use the deprecated JS function "escape" anymore. Use encodeURI instead:
<script>
function sendAnnotatedMailTo(name, company, domain, subject, body) {
locationstring = 'mai' + 'lto:' + name + '#' + company + '.' + domain + "?subject=" + encodeURI(subject) + "&body=" + encodeURI(body);
window.location.replace(locationstring);
}
</script>

Jquery or Javascript Redirect to Controller/Action

I have the following code which works on the first time around:
$("#CompDD").change(function () {
//var parts = (window.location.pathname.split("/"));
var ctrlName = '#ViewContext.RouteData.Values["Controller"].ToString()';
var actnName = '#ViewContext.RouteData.Values["Action"].ToString()';
var url = (ctrlName + "/" + actnName + "/?SearchString=" + $('#CompDD option:selected').text() + "&atton=" + $('#AttDD option:selected').val());
//delete ctrlName;
// delete actnName;
//window.location = ($(location).attr('href') + "/?SearchString=" + $('#CompDD option:selected').text() + "&atton=" + $('#AttDD option:selected').val());
//window.location = (ctrlName + "/" + actnName + "/?SearchString=" + $('#CompDD option:selected').text() + "&atton=" + $('#AttDD option:selected').val());
//$(location).attr('href', url);
window.location.href = url;
//alert(ctrlName + "\n" + actnName);
});
However on subsequent changes of the drop down in question (#CompDD) it will add another controller/action to the end of the link, ex. it adds another "Patrons/Index" to the end of the existing "Patrons/Index", thenit adds the searchsrting variables etc.
Please excuse the comments and stuff on my code. How do i get Jquery (or javascript) to redirect without appending the controller name and action names over and over, or whats the best way to do this?
EDIT: Such an easy fix! I had to add the root slash to the URL string, example this worked:
var url = ("/" + ctrlName + "/" + actnName + "/?SearchString=" + $('#CompDD option:selected').text() + "&atton=" + $('#AttDD option:selected').val());
Notice the forward slash at the start of the string I construct....Yikes!
Use the Url.Action helper method to build path to action methods.
$("#CompDD").change(function () {
var baseUrl="#Url.Action("Home","Search")";
alert(baseUrl);
// Now append your query string variables to baseUrl
// Ex : baseUrl=baseUrl+"?searchString=testing";
window.location.href=baseUrl;
});
Assuming you want to navigate to the search action method in Home controller.
function RedirectUrl() {
if (domElement.textfor.val() == "Index") {
window. location.href = E_host.AppVar.AppHost + "/Home/index";
}
}

JavaScript window.location.href not working

I'm trying to redirect to a new URL using window.location.href which does not seem to work for a particular URL.
The page URL is: http://localhost:37368/Office/Search/c2VhcmNoaWRzPTEyMiwxMjIsMTI0LDE1OCwzNzl8bG9jYXRpb25pZHM9MSwyfGZyb21pZHM9fHRvaWRzPQ==
Upon a button click, something happens using an AJAX post, and the URL is changed, via JavaScript, to http://localhost:37368/Office/
However, the page always redirects back to the previous one.
The JS code:
onClear: function (event) {
//.... omited for purpose of question
var $controller = (event.data.object.settings.controller === undefined) ? '' : event.data.object.settings.controller
$new_url = window.location.protocol + '//' + window.location.host + '/' + $controller;
window.sessionStorage.clear();
window.location.href = $new_url;
}
Try to add to new URL some random parameter to avoid caching or other bugs:
$new_url = window.location.protocol + '//' + window.location.host + '/' + $controller + '?r=' + ("" + Math.random()).substr(2, 4);

tinyMce shortcuts

I am working with an asp.net website where we have implemented shortcuts in our page master, but these don't seem to work when the tinymce editor has focus. is there any way to solve this issue? it doesn't matter if it's at master page level or tinymce-level.
I have tried to create custom methods via the addShortcut method but this causes my javascript to error.
page.ClientScript.RegisterStartupScript(page.GetType(), new Guid().ToString(), "ShortCutModule();", true);
string enableShortcuts = #"function enableShortcuts(){"+
#"tinyMCE.get('"+"myKey2"+this.ID+#"').addShortcut(""Ctrl+Shift+f12"",""nix"",""jourcut"");";
page.ClientScript.RegisterStartupScript(page.GetType(), new Guid().ToString(), enableShortcuts, true);
page.ClientScript.RegisterStartupScript(
page.GetType(),
"MyKey2" + this.ID, #"<script type=""text/javascript"" >" +
#"tinyMCE.init({" +
#"oninit : ""enableShortcuts"","+
#"mode: ""exact""," +
#"elements: """ + this.ID + #"""," +
#"theme: ""advanced""," +
#"plugins: ""spellchecker,advhr,insertdatetime,preview""," +
#"theme_advanced_buttons1: ""bold,italic,underline,|,outdent,indent,|,cut,copy,paste,|,undo,redo""," +
#"theme_advanced_toolbar_location: ""top""," +
#"theme_advanced_toolbar_align: ""left""," +
#"theme_advanced_statusbar_location: ""bottom""," +
"custom_shortcuts : false," +
"theme_advanced_path : false," +
"setup : function(ed) {" +
"ed.addCommand('jourcut', function() {CutFromJournal();});" +
"}" +
"});" +
"</script>",
false);

Making a function work in HTTP and HTTPS

I have this Javascript code I inherited from another developer. I am very new to Javascript.
The problem I'm having is that it won't work when the user is in HTTPS. Is there a workaround for this problem?
var tier1CategoryLink = "http://" + window.location.hostname + "/categories/";
$("#as_Placeholder").load(tier1CategoryLink + " .SubCategoryList > ul", function(){
$('#tier1').find('option').remove().end().append('<option>Make</option>');
$("#as_Placeholder ul li").each(function(){
var thisText = $(this).children("a").text();
if ((thisText != "All Products") && (thisText != "Best Selllers") && (thisText != "Chromoly Flywheel Combo Sale") && (thisText != "New Arrivals") && (thisText != "On Sale") && (thisText != "Needs Categories")) {
$("#tier1").append("<option value='" + $(this).children("a").attr("href") + "'>" + thisText + "</option>");
}
});
});
Use window.location to determine user's current protocol and adjust accordingly:
var tier1CategoryLink = window.location.protocol + "//" + window.location.hostname + "/categories/";
Or just use relative URL:
var tier1CategoryLink = "/categories/";
I guess you want to say that you get a java-script error in the browser. And that is expected too. When the user is in https then you have to amend the java-script to include https. For eg your first line must look like this:
var tier1CategoryLink = "https://" + window.location.hostname + "/categories/";
EDIT: Moreover you can have a look at this to solve your issue.
Detect HTTP or HTTPS then force HTTPS in JavaScript
Easiest solution is to just use double slashes
var tier1CategoryLink = "//" + window.location.hostname + "/categories/";
Details in spec Section 5.2

Categories