I use this code in my login panel in MVC3:
#Html.PasswordFor( m => m.Password, new { maxlength = 10 } )
I want to do that, somebody cannot to PASTE any password to PasswordFor.
(To enter password ONLY with typing)
what must i do?
You probably shouldn't do as it completely sucks from user's perspective but if you want your users to hate you, you could do this:
$('#Password').bind('paste', function(e) {
e.preventDefault();
});
Something like:
var pw = document.getElementById("Password");
pw.addEventListener("paste", function(event)
{
event.preventDefault();
}
... with equivalent event listening and default prevention for IE etc.
jQuery:
$("#Password").bind("paste", function(event)
{
event.preventDefault();
});
Neither will work on Opera.
But then, you shouldn't be doing it in any event. My personal way of "pasting" passwords is way more secure than you tampering with my browser's default user experience. And you're messing with my method, which is likely to make me pick a less secure password specifically for your site. Or not use it.
You can use like this
$(document).ready(function(){
$('#Password').live("paste",function(e) {
e.preventDefault();
});
});
Related
I have a website, in which when user clicks a link it opens up in the same window if it is of my website's page, else in new window if domain is different. But I am doing this manually like this:
Open Link
checkdomain() checks the domain name of the link and returns true if it's of my website else false. I used the code from [ HERE ] for this purpose.
My question is: Is there any efficient and client side way available for checking link domains and open up them in new windows/tab if of another website(domain)? Like a JavaScript solution will be better, but then again JavaScript can be disabled by user. So, is there any other solution? Even JS solution will be great. Ignoring the disabling by user.
Somewhere on the page, or in an external JS file:
function externalLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i = 0; i < anchors.length; i++) {
var anchor = anchors[i];
if (anchor.getAttribute("href")
&& anchor.getAttribute("rel")
&& anchor.getAttribute("rel").indexOf("external") >= 0)
anchor.target = "_blank";
}
}
window.onload = function() {
externalLinks();
};
Then, any external links just need to have rel="external" in the markup. For example:
Click here!
The main advantages of this approach is that you're not going to cause any validation errors, even with an XHTML Strict doctype. Users are also able to easily prevent links opening in new windows by simply disabling JS.
If you need the decision of external/internal to be made automatically (and client-side), you can alter the logic of externalLinks to base the decision on the href attribute rather than the rel attribute. Of course, if you've already got the external/internal logic functioning in your codebehind, I would recommend using that information to render the anchor with the appropriate semantics (with rel), rather than re-writing almost identical code in your client-side JS.
Try comparing your link url's host part (www.wrangle.in) with following in you function logic.
string currentURL = HttpContext.Current.Request.Url.Host;
I do not recommend to compare the name (i.e http or https), you can split using substring function.
For Client side
var homeURL = document.location.hostname;
$('a').each(function() {
if ( $(this+'[href*='+homeURL+']')) {
$(this).attr('target','_self');
}else{
$(this).attr('target','_blank');
} });
This link may help you to understand Url Parts.
I am studying the following example of signalR
http://www.asp.net/signalr/overview/getting-started/tutorial-getting-started-with-signalr-and-mvc-4
I want to implement it, and well the code is there, however I dont want the user to type the username in a prompt window, I am going to make the page available for logged in users, therefore I will have the context.User.
I would like to change the prompt part to use the context.User from the server side but I have no idea how.
thanks a lot
$('#displayname').val(prompt('Enter your name:', ''));
You could provide the information on page load or retrieve it via AJAX. I'd suggest the former.
Depending on your view engine, something like...
$('#displayname').val('#(Context.User.Replace("'", "\\'"))');
or Better, provide it as a property of your view model so it would be
$('#displayname').val('#(Model.User.Replace("'", "\\'"))');
I've used the following code. However, it doesn't redirect you to another page. But, it makes the login window invisible as the user log in to application and it displays the chat room. Hope this helps.
$(function () {
setScreen(false);
var chatHub = $.connection.chatHub;
registerClientMethods(chatHub);
$.connection.hub.start().done(function () {
registerEvents(chatHub)
});
});
function setScreen(isLogin) {
if (!isLogin) {
$("#divchat").hide();
$("#divLogin").show();
}
else {
$("#divchat").show();
$("#divLogin").hide();
}
};
// If the user is Authenticated shows de nick if not sets it to invitado + random number
if (Request.IsAuthenticated) {
$('#displayname').val(User.Identity.GetUserName());
} else {
$('#displayname').val("invitado" + Math.floor((Math.random() * 100) + 1));
// $('#displayname').val(prompt('Enter your name:', '')); (Alias Window... what you had)
}
I am using Facebook like in my web page. The url to be posted is having query string like
http://test.something.in:302/sample.aspx?id=54
but it is truncated while posted in facebook and the url became
http://test.something.in:302/sample.aspx.
Can anyone please help me to solve this?
<body>
<div id="fb-root"></div>
window.fbAsyncInit = function () {
FB.init({
appId: '451971411518111',
status: true,
cookie: true,
xfbml: true
});
};
(function (d, debug) {
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) { return; }
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all" + (debug ? "/debug" : "") + ".js";
ref.parentNode.insertBefore(js, ref);
}(document, /*debug*/ false));
<form id="form1" runat="server">
<div class="fb-like" data-href="http%3A%2F%2Ftest.something.in%3A302%2Fsample.aspx%3FId%3D54" data-send="false" data-width="450" data-show-faces="true"></div>
</form>
If I understand your question correctly, you have to encode the link when you pass it to the Facebook Direct FB URL.
A good online encoder can be found at W3Schools:
http://www.w3schools.com/tags/ref_urlencode.asp
The JavaScript function http://www.w3schools.com/jsref/jsref_encodeuri.asp is also good for encoding your URLs on the fly, though I have no clue about what function to use in C# (Don't ask me about C# as I have never coding one character on C#. I don't even know if it has functions. :P)
For example, the URL you provided would be encoded something like this:
http%3A%2F%2Ftest.something.in%3A302%2Fsample.aspx%3Fid%3D54
Tell me if this works.
BTW this question is basically a duplicate of Facebook URL truncated. Try to avoid duplicates in the future. They can lead to closures of your question, a lot of downvotes (which I was nice enough not to do) and even a temporary ban. Don't worry about it now, just for the future.
I am making a marketing tool that is required to register facebook accounts using web requests. I have been trying to understand the protocol but I always end up with a "Sorry there is something went rong" page. Any explanations are appreciated =].
Regards
edit: I am trying to let the user to register on facebook through my application. He should input the required fields (names,birthday,email) and the application should do the signup process for him after he solves the captcha that will be fetched from facebook. It's not a spam attempt, Don't bother saying you won't answer because it's a spam attempt. If you think so, just don't answer.
edit: I don't want to use any WebBrowser controls, I need it to be through HTTP Requests.
edit: I try to imitate requests sent to facebook from my computer using fiddler, I believe I imitated everything that facebook website does. Though I still getting "Sorry something went wrong" page.
You have several API to to that. I recommend that you use the last one, the graph API. Then you have several SDK, I know PHP and Javascript SDK.
In javascript, with jQuery you can do
<body>
<div>
<button id="login">Login</button>
<button id="logout">Logout</button>
<button id="disconnect">Disconnect</button>
</div>
<div id="user-info"></div>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
// initialize the library with the API key
FB.init({ apiKey: 'YOUR_API_KEY' });
// fetch the status on load
FB.getLoginStatus(handleSessionResponse);
$('#login').bind('click', function() {
FB.login(handleSessionResponse, {
// here you specify the perms your application requires
perms:'publish_stream, offline_access, manage_pages, read_stream'
});
});
$('#logout').bind('click', function() {
FB.logout(handleSessionResponse);
});
$('#disconnect').bind('click', function() {
FB.api({ method: 'Auth.revokeAuthorization' }, function(response) {
clearDisplay();
});
});
// no user, clear display
function clearDisplay() {
$('#user-info').hide('fast');
}
// handle a session response from any of the auth related calls
function handleSessionResponse(response) {
// if we dont have a session, just hide the user info
if (!response.session) {
clearDisplay();
return;
}
// if we have a session, query for the user's profile picture and name
FB.api('/me/accounts', function(response) {
$('#user-info').html(JSON.stringify(response));
});
}
</script>
</body>
This example is taken from the documentation of the JavaScript SDK. You need to get you API_KEY from the facebook developper page http://www.facebook.com/developers/apps.php
I need to refresh sections of my page to update when there is new data! what do i do? use jquery?
examples:
Yes, jQuery's great for this. Look into these methods:
http://api.jquery.com/category/ajax/
jQuery is usually not needed for basic AJAX. A simple example could be as follows:
liveSection = document.getElementById('latest-news');
request = new XMLHttpRequest;
request.open('GET', '/news-ajax', true);
request.send(null);
request.addEventListener('readystatechange', function() {
if (request.readyState == 4 && request.status == 200)
liveSection.innerHTML = request.responseText;
}, false);
If you're using Asp.NET, why not use an UpdatePanel? It's simple and reliable.
Edit
I just re-read your question and it looks (based on how you worded it) that you want to update a user's web page when the data changes on the server. I just want to make sure you understand that in a web app, the server can't trigger the browser to do anything. The server can only respond to browser requests, so you'll need to have the browser poll the server periodically.
I've created a simple example (using jQuery) to help you understand the breakdown of the things that will need to happen, which are:
1 - Periodically polling the server (via ajax) using Javascript's setTimeout to check that what is loaded into the browser is the latest content. We can achieve this by fetching the latest item ID or whatever and comparing it to a variable, which was initialised when the page first loaded.
2 - If the item ID does not match (a bit of an oversimplification) then we can assume that there has been an update, so we replace the content of some element with some content from some page.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
function getLatestStuff() {
// fetch the output from a context which gives us the latest id
$.get("isthereanupdate.aspx", function(response) {
// we have the response, now compare to the stored value
if(resp != lastItemId) {
// it's different, so update the variable and grab the latest content
lastItemId = response;
$("#latestStuffDiv").load("updates.aspx");
}
});
}
$(document).ready(function() {
// the value which initializes this comes from the server
var lastItemId = 7;
setTimeout(getLatestStuff, 10000);
});
</script>
If you want to update when there is new data, you should look into comet or pubsubhubbub. jQuery can help you display the data in a pretty way, but you'll need to write stuff on the serverside to send the data.