actually I'm developing on Intel XDK IDE, but I need redirect to other page.
Thanks.
Code:
$(document).on("click", "#ini-sesion", function(evt)
{
var user = $("#user").val();
var pass = $("#pass").val();
if (user == "admin" && pass == "123"){
intel.xdk.notification.alert( user + " - " + pass, "Data", "Ok");
window.location.href = "#sales";
}else{
intel.xdk.notification.alert( "Pass & User Incorrect", "Alert!", "Ok");
}
});
This:
window.location.href = "#sales";
won't work, cause href needs an URL, not a CSS selector.
You need to have a web protocol (http:// or https://), or something like this:
window.location.href = "sales.html";
This works for me:
activate_subpage("#sales");
Related
I have an ashx receiving login/password and send error message if it's wrong but if it's good make a RedirectFromLoginPage.
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
FormsAuthentication.SignOut()
Dim LesDatas As New MyEntities
Dim username As String = GetParamURL("UserName")
Dim password As String = GetParamURL("Password")
If Not IdentifyCollab(username, password, LesDatas) Then
FormsAuthentication.SignOut()
context.Session.Abandon()
HelperJournal.Log("Echec de connexion :" & username)
loginStatut = LoginFailed(GetIPAddress, LesDatas)
context.Response.ContentType = "text/plain"
context.Response.Write(loginStatut.Msg)
Else
FormsAuthentication.RedirectFromLoginPage(ConnectedUser.Login, False)
End If
End Sub
If You use directly the ashx in browser url zone : http://localhost:5959/login/login.ashx?UserName=toto&Password=MyPass, you're directly redirect in the default page http://localhost:5959//choix.aspx
But If I call it from JS :
$.post("/Login/Login.ashx?UserName=" + mdp1 + "&Password=" + mdp2, {},
function (response,tt,ti) {
if (response.indexOf("html") === -1) $("#ResultConnexion").html(response); else {
window.history.pushState("", "", '/choix.aspx');
var newWindow = window.open("", "_self");
newWindow.document.write(response);
}
});
I need to use pushState to correct the url in browser, and window.open/write to display the defaultpage. But like you can see, I write in hard "/choix.aspx", cause the url are not modify and stay on referer URL (my login page http://localhost:5959/Login/login.html)
But If I can have automaticly the good URL when I use in browser my ashx, it's seems the URL information is sent.
In function use in response of $post I note severals parameters : response,tt,ti
response is the text to display page in return
tt="success"
ti is an object with lot of informations... but I don't see where is URL.
If someone can help me.
I just find a way here
In my masterpage
Private Sub Choix_Init(sender As Object, e As EventArgs) Handles Me.Init
Response.AppendHeader("X-MONAPPLI", HttpContext.Current.Request.Url.PathAndQuery)
End Sub
and in login.js
$.post("/Login/Login.ashx?UserName=" + mdp1 + "&Password=" + mdp2, {},
function (response, tt, xhrreq) {
if (response.indexOf("html") === -1) $("#ResultConnexion").html(response); else {
window.history.replaceState("", "", xhrreq.getResponseHeader("X-MONAPPLI"));
var newWindow = window.open("", "_self");
newWindow.document.write(response);
}
});
I use replaceState instead of pushstate cause I've secyrity error
window.location will redirect to external links like google, but won't redirect to a url with the same domain from where it originates (it'll link to sub-domains, though). This came from a hubspot form, customized to redirect the user to a specific thank-you page based on their inquiry type. This is all in wordpress. There is no issue defining the choice variable. I'm new to JavaScript, thanks for any help.
onFormSubmit: function($form) {
var choice = $('select[name="form_field_dropdown_select"]').val();
if (choice == 'Support') {
window.location = 'https://www.mycompany.com/support-thank-you/';
} else {
window.location = 'https://www.washingtonpost.com/';
}
}
I'm running this code through my console because I know the choice variable is set up correctly. The error I'm getting is an Uncaught SyntaxError: Unexpected token ( on the line onFormSubmit: function($form)
onFormSubmit: function($form) {
var choice = "Support";
if (choice == 'Support') {
window.location = 'https://newcloudnetworks.com/support-thank-you';
} else {
window.location = 'https://www.washingtonpost.com/';
}
}
Additionally, I can see the redirect initially going to the support page but then immediately redirecting to the default/home page.
[21/Mar/2019:11:13:44 -0600] "GET /support-thank-you HTTP/1.1" 200 6015
[21/Mar/2019:11:13:46 -0600] "GET / HTTP/1.1" 200 9683
The issue has been resolved. It was an issue I had to raise hell with to Hubspot and they were able to resolve. It had nothing to do with an error in the JS code. Thanks.
So, you need to provide more info, but I'll assume your:
hostname(domain): www.mycompany.com
So you can add another check for the domain the form was used.
const myDomain = 'www.mycompany.com';
onFormSubmit: function($form) {
var choice = $('select[name="form_field_dropdown_select"]').val();
if (choice == 'Support') {
let domain = window.location.hostname;
if (myDomain == domain) {
// change path if the form is used in your domain
window.location.pathname = 'support-thank-you';
} else {
// redirect to you domain
window.location = 'https://www.mycompany.com/support-thank-you/';
}
} else {
window.location = 'https://www.washingtonpost.com/';
}
}
I am using a javascript form script and I want to redirect to an external website. I set the redirect to www.paypal.me but it actually redirects the user to www.mysite.com/www.paypal.me
How can I edit the code below to instead redirect the user to the actual site, not prefaced by my own URL?
var redirect = "www.paypal.me";
...
this.submitOK = function(){
if( redirect == '' ){
showThankYouMessage();
return;
};
try{
if( parent ) parent.location.href = redirect;
}catch(e){
location.href = redirect;
};
}
}
Here you can find a small overview over the redirect methods in js: https://appendto.com/2016/04/javascript-redirect-how-to-redirect-a-web-page-with-javascript/
To a redirect use something like this:
<script>
var locationn = "https://google.com";
window.location = locationn;
I have searched quite a lot regarding my problem and I couldn't find any relevant tutorial. Moreover, I am not even sure if it is possible using client side technology.
Problem statement: For e.g I have many pages in my web app and if a user switch from index page to page 1 and then page 2. Now the user decides to login to my web site. I want to redirect the user to page 2 once the login is successful.
Current outcome: Once the login is successful user always seems to get redirected to the index page.
Desired outcome: Once the login is successful the user should stay on page 2.
Is it possible using client side technology? In PHP we could use sessions and all. But I am confined on using client side technology to achieve that.
Here is my login function
function login(params) {
if(checkEmpty("loginEmail") && checkEmpty("password")) {
var emailField = $("#loginEmail").val(),
passwordField = $("#password").val(),
data = "login=" + emailField + "&password=" + passwordField;
for (var key in params) {
data += "&" + key + "=" + params[key];
}
// Hide errors as default
$("#loginErrorWrapper").hide();
// Try to launch the "normal" submit operation to make browser save email-field's value to cache
$('#loginSubmitHidden').click();
// Send data to server and refresh the page if everything is ok
$.when(loginPost(data)).done(function(map) {
if(!hasErrors(map)) {
var lang = map.language;
if (lang != "") {
changeLanguage(lang)
}
else {
lang = 'en';
}
redirect("/" + lang + "/");
} else {
if (map.errorCode == "155") {
$.fancybox({
href : '#termsAcceptancePopup',
title : '',
beforeLoad : function() {
$('#acceptTermsButton').attr('onclick','javascript:login({policyChecked:true});$.fancybox.close();');
},
helpers : {
overlay : { closeClick: false }
}
});
} else {
var errorString = getErrorMessage(map);
$("#loginErrorWrapper").show();
$("#loginErrorWrapper").html(errorString);
}
}
});
}
}
Ajax request
function loginPost(data) {
return $.ajax({
url: "/some-api/login",
type: "POST",
dataType: "json",
contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
async: true,
data:data
});
}
P.S -> I am not using PHP at all. I am working on a Java based web app.
So I have tried all the methods suggested in the comment section and all of them worked.
1) Using location.reload()
Once the user is logged in it just refresh the page.
2) Saving the last URL in a cookie
Calling the below function before calling redirect.
createCookie(value1, value2, value3);
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
3) Removing redirect("/" + lang + "/"); from my function since I am using ajax for login. However this method is not useful because once the user is logged in he/she will never know whether everything went fine or not unless he/she refresh the page manually or go to another page.
I am not certain which method is better (performance and loading time) - method 1 or method 2.
I have a textbox where the user can enter URL and button named Check link. On clicking button, a new window should be opened with the URL entered by the user. If i enter URL as "http://google.com" then window.open('http://google.com'); is working fine but if i enter "www.google.com" then it is appending to the current window url (http://localhost:1234www.google.com) which is not a valid url. How to make this work?
Thanks in advance
Check & prepend
if (!/^(http:|https:)/i.test(url))
url = "http://" + url;
try this:
function f(url) {
if (url.indexOf("http://") == -1) {
url = "http://" + url;
}
window.open(url);
}
If your question is "How do I test if a string starts with 'http://' and if not prepend it?" then something like this:
var url = "somestring.com"; // as set from your textbox
if (0 != url.toLowerCase().indexOf("http"))
url = "http://" + url;
It would be wise to trim leading and trailing spaces before doing this test, but I'll leave that as an exercise for the reader...
Add a onclick button function and handle the text in that.
function checkLink() {
var url = document.getElementById("textbox-id").value;
if(url.substr(0,7) != "http://") {
alert("Invalid URL! Please make it like http://myurl.com");
return false;
}
}