I am using the below javascript code to open the LinkedIn url with some french content.
var link = 'http://www.linkedin.com/shareArticle?mini=true&url=' + url + '&title=' + title + '&summary=' + summary + '&source=testing';
window.open(link, 'share_it', 'width=520,height=570');
But its working fine in chrome with below french contents but not working in IE 11. Its giving the 404 bad request error.
http://www.linkedin.com/shareArticle?mini=true&url=http://testing/&title=PageTitle&summary=énergétique&source=testing
EDIT:
I have tried with encodeURI it opening the window but after logged in the summary is not getting displayed the title only getting displayed. What to do on this one.
Can anyone tell me what i have done wrong.?
I just tried to use it on IE10. The issue is because of the characters in the french language that you must encode. To solve the issue simply use encodeURI() function and you won't get the Bad Request error.
var link = 'http://www.linkedin.com/shareArticle?mini=true&url=' + url + '&title=' + title + '&summary=' + summary + '&source=testing';
link = encodeURI(link);
window.open(link, 'share_it', 'width=520,height=570');
I tested it, and it was working fine for me on IE10 as well.
Related
I needed to help with a feature I have never seen before. I do not even know if it exists, but you may have met.
I'm referring to the shortcuts in the browser and I would like to add another shortcut to "add 'this' to the end of the url".
Example:
I am on www.example.com and click on the link in the shortcut bar to redirect me to www.example.com/redir1. If I'm on www.example2.com and click on the same link, it redirects me to www.example2.com/redir1.
I manage a number of sites and I have to click on "Settings/blah blah/page/" takes a few minutes. By linking, I would like to get straight to the "page" so I do not have to click and load pages before this one so many times.
You may use a Bookmarklet.
Bookmarklets are (small) chunks of JavaScript, that will be executed when clicking the bookmarked link. I use them for quick navigation in ticket systems.
Maybe this example solves your problem.
Of course, you have to condense your JavaScript to just one line, so it fits into the address line of the bookmark.
javascript:(function(){open(window.location.protocol + "//" + window.location.hostname + "/redir1");})();
You can even open a JavaScript prompt for retrieving some kind of user input. The next example asks the user where he wants to go and modifies the link respectively.
javascript:(function(){var relPath=prompt('Where do you want to go?'); open(window.location.protocol + "//" + window.location.hostname + "/" + relPath);})();
I tested this one in the current versions of Firefox and Chrome. Just add a new bookmark and use the JavaScript Code instead of any URL.
Additional examples, as requested in comments.
For the sake of readability, I present the second one in multiple lines, please remove the line breaks before trying to use it as a bookmarklet.
The first example navigates from
protocol://sub.domain.tld/any/possible/path/somewhere.xyz to
protocol://sub.domain.tld/web1/site/site.xml.
javascript:(function(){open(window.location.protocol + "//" + window.location.hostname + "/web1/site/site.xml");})();
The second example navigates from
protocol://sub.domain.tld/keep/this/any/site.xml to
protocol://sub.domain.tld/keep/this/another/resource.
If window.location does not contain a long enough path name, the navigation will not work, because the script will just add "undefined" in the target URL.
javascript:(function(){
var pathNameAsArray = window.location.pathname.split('/');
var pathToKeep = "/" + pathNameAsArray[1] + "/" + pathNameAsArray[2];
open(window.location.protocol + "//" + window.location.hostname + pathToKeep + "/another/resource");})();
I'm creating a ics string in my app with this code:
var icsMSG = "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//Our Company//NONSGML v1.0//EN\nBEGIN:VEVENT\nUID:me#google.com\nDTSTAMP:" + today
icsMSG = icsMSG + "\nATTENDEE;CN=My Self ;RSVP=TRUE:MAILTO:me#gmail.com\nORGANIZER;CN=Me:MAILTO::me#gmail.com\nDTSTART:" + start +"\nDTEND:" + end +"\nSUMMARY:" + $scope.eventContent.text + "\nEND:VEVENT\nEND:VCALENDAR";
This is working fine, since when I want to download on my PC it works fine.
For downloading in PC I'm using
window.open( "data:text/calendar;charset=utf8," + escape(icsMSG));
Apparently this does not work on mobile. On iPhone it does not recognize the file, in Android it downloads the file and you must open it to add to calendar.
I read about webcal:// But it seems to not work sending the string after the webcal://
How can I set the download click in mobile
The spec-compliant newline sequence is \r\n. I doubt that's the problem, but you could try it.
Also, you could try charset=utf-8 (add the dash).
Also note that you have an extra colon character in one of your "mailto" URIs.
I've read a few answers, and tried a bit of different code from them, but haven't been able to solve this. I am a newbie at this and it seems like quite a simple thing to do, apologies if the answer is really obvious, just need it to work really..
So far, I have an aspx page in Visual Studio 2010 / it was created by someone else, and has both JavaScript and cSharp code behind it.
What I would like to happen is that, an 'Edit' button appears on the page in a table in the correct place, and as a result of pressing it, another page is called allowing the editing (of contacts - it's an internal website).
I can get the link working OK as a 'normal' hyperlink, using this line of code:
var editcontact = '<td align = "right" colspan = "40" class =
"contactBorder"><a href="WebForm1.aspx?supplier_id=' +
dataRow.supplier_id + '">Open Contact(s) For Edit</a></td>';
edit contact then gets put in a table like structure (maybe it's "form" given the HTML tags):
finishedcontacts += openrow + contactid + contactname +
contactjobtitle + contactlocation + contacttelephone +
contactemail+ editcontact + '</form></tr>';
That's OK but it's not very 'nice', what I would like is an actual edit button, I can get the button to appear, but the last time I tried it pressing it does nothing:
var editcontact = '<asp:button id = "editImage4" runat="server"
Text="Click me"
OnClientClick="window.open(\'WebForm1.aspx\\?supplier_id=\' + dataRow.supplier_id + \', \'WebForm1\');" />';
Any ideas on how to get this working OK from a button?
Here is some other code I tried, which was to separate out the generation of the url from the calling code, but none of them seemed to work:
//var url = string.Format("{0}?supplier_id={1}", "../WebForm1.aspx", dataRow.supplier_id);
//var url = string.Format("{0}?supplier_id={1}", #"../WebForm1.aspx", dataRow.supplier_id);
//var url = 'string.Format("{0} supplier_id={1}", "WebForm1.aspx",'+ dataRow.supplier_id +')';
var url = 'WebForm1.aspx?supplier_id= '+ dataRow.supplier_id +'';
var supplierid1 = dataRow.supplier_id;
Any ideas what be greatly appreciated. This is my first ever post..
Use Response.Redirect(url) if you want to redirect using your button and this button must be a server side control.
In the end, a colleague helped me out with this.
As other posters identified there was some problems with the URL, and especially with the escapes.
Anyway below is the code in the unlikely event anyone needs something similar.
buttoncode = '';
var editcontact = '' + buttoncode + '';
And we added a function (which should probably be called a method or whatever):
function OpenContactForEdit(supplier_id)
{
window.location = "WebForm1.aspx?supplier_id=" + supplier_id;
}
Comments:
This bit is very important:
onClick="OpenContactForEdit(\'' + dataRow.supplier_id + '\')"
Note exactly how we needed to escape (and 'end escape') the single quotes.
I believe that was quite a big part of why, what I was doing was not working.
I'm using the Facebook Javascript SDK to post on my page, i've already read something about this here: Facebook feed dialog: allow user to select destination page or group so I've been using this code so far:
$("button#shareOn").on('click',function(event){
event.preventDefault();
var _parentForm=$(this).parents('form:first');
var _pageSelect=_parentForm.find("select[name='pagesList']");
var _pID=_parentForm.find("#pID").attr('value');
var _vURL=_parentForm.find("#_vURL").attr('value');
FB.ui({
app_id:app_id,
method: 'feed',
from: _pageSelect.val(),
name: 'Title',
caption: 'Subtitle - 26/02/2013',
description: 'My text',
link: _vURL,
},function(response){
console.log(response);
});
});
Where _pageSelect.val() is the ID of the page in which I'm trying to post, _vURL is the url ( youtube link ) which I want to share... The problem is that when I click on the button, a window opens up, but's actually blank.
By opening Google Chrome's dev console, sometimes I see a 500 Internal Server error related to that window and sometimes it only comes up totally empty, but I can't figure out what is actually causing it.
I've also tried urlencode the url from PHP or encodeURIComponent from Javascript, but nothing as changed at all.
Sometimes the window comes up only with Title, Subtitle and Description, so I guess the link should be the error, but I knew that Facebook JS SDK used to write Link not properly formatted or something like API error (100).
UPDATE
It seems that Feed dialog has started collaborating, but still not working as expected. This is the updated code:
$("button#shareOn[name='shareVideo']").on('click',function(event){
event.preventDefault();
var _parentForm=$(this).parents('form:first');
var _pageSelect=_parentForm.find("select[name='pagesList']");
var _pID=_parentForm.find("#pID").attr('value');
var _vURL=_parentForm.find("#_vURL").attr('value');
var options={
app_id:app_id,
method:'feed',
from:_pageSelect.val(),
link:_vURL,
caption:'test'
}
console.log(options);
FB.ui( options, function(response){});
});
The window is opening, but sometimes it's blank and sometimes shows a link, which is not the url of the video, but it's just www.youtube.com. I've been trying with the Facebook URL Debugger and it's showing me that the URL which I'm using is actually right. But feed dialog just doesn't work
So, I've got the answer, which isn't really what I was expecting, but at least it works. As the Facebook docs aren't pointing to this, I've found the sharer method, which I call in a Javascript function.
So, this is the code:
$("button#shareOn[name='shareVideo']").on('click',function(event){
event.preventDefault();
var _parentForm=$(this).parents('form:first');
var _pageSelect=_parentForm.find("select[name='pagesList']");
var _pID=_parentForm.find("#pID").attr('value');
var _vURL=_parentForm.find("#_vURL").attr('value');
var leftPosition, topPosition;
var windowFeatures = "status=no,height=" + 400 + ",width=" + 300 + ",resizable=yes,left=" + leftPosition + ",top=" + topPosition + ",screenX=" + leftPosition + ",screenY=" + topPosition + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no";
leftPosition = (window.screen.width / 2) - ((300 / 2) + 10);
topPosition = (window.screen.height / 2) - ((400 / 2) + 50);
window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(_vURL),'sharer', windowFeatures);
return false;
});
By the way, I don't like this method, but it seems like the only way to accomplish what i was trying to do. Now I just need to know how to get the result of the sharing function ( if the post was shared or not ).
Hope this will help someone :)
I have a problem with window.location.href.
I'm trying to redirect to a page with the following code:
window.location.href = "juego.html"+'?modoJuego='+modoJuego+"&etapa="+etapa+"&rango="+rango;
It works perfectly on Firefox and Chrome, however in IE10 the browser freezes and I have to restart it. Sometimes it redirect to the desired page, but the parameters do not pass through. I have been looking for a solution, for example this one:
Window.Location Not Working In IE?
But the proposed solution do not work for me.
Do somebody know how to deal with this?
The problem is likely due to the value of your variables. If they contain special or invalid characters, those needs to be passed through encodeURIComponent before being assigned to window.location.href.
For some reason IE only like full url.
I have te same problem and fix it adding the full url like this:
var baseURL = 'http://www.your_url.com/';
window.location.href = baseURL + "juego.html"+'?modoJuego='+modoJuego+"&etapa="+etapa+"&rango="+rango;
Use encodeURIComponent() to escape your url:
window.location.href = encodeURIComponent("juego.html?modoJuego=" + modoJuego + "&etapa=" + etapa + "&rango=" + rango);
Works fine on Firefox 23.0, Chrome 28.0.1500.95 and Internet Explorer 10.
Try window.location.replace(...) instead.
Refer this question for information:
How to redirect to another webpage in JavaScript/jQuery?