Page 1 of 1
Redirect to index.html in case of an error
Posted: Wed Oct 07, 2020 9:30 am
by Theju112
I have a requirement where I need the user to be re-directed to the index.html page of a phone-gap app incase of an error.
Below is the Javascript snippet where this action must be executed.
Code: Select all
// IF NO URL, GO BACK TO INDEX
if (url == '""')
{
// leave login screen and load main app screen
//**PAVT --> Alert user of incorrect credntials.
alert("Incorrect user name or password!");
};
The file containing the above code is placed in the folder app/www/js. The index.html file is placed in the www folder.
So I tried adding the below line:
Code: Select all
window.location.href=pui.normalizeURL("index.html");
But I get a run time error which says "file not found."
I have used another js program as reference which seems to be doing the same thing.
The code in my reference program, also in the JS folder is:
Code: Select all
window.location.href=pui.normalizeURL("DriverMain.html");
where DriverMain.html is also in the www folder and this seems to be working fine.
I have also tried using random things like which also doesnt work..
window.location.href=pui.normalizeURL("
http://iesaccess.com:8080/profoundui/us ... _AUTH.json")
Can someone please guide how to achieve this?
Re: Redirect to index.html in case of an error
Posted: Wed Oct 07, 2020 10:23 am
by Scott Klement
You definitely don't want to be calling pui.normalizeURL() -- that will put your IBM i location into the URL, and you stated that you want the index.html from within the app, right?
Can you explain what you're trying to accomplish by redirecting to index.html?? This is a very strange thing to do.
Re: Redirect to index.html in case of an error
Posted: Wed Oct 07, 2020 10:52 am
by Theju112
In this scenario, the index.html page is the starting point of the app.
Below is from the config.xml.
<content src="index.html" />
This runs a script appLogin.js which renders the sign-in form to the user. The code has been written in such a way that if the user enters a non blank user id and password, user would be re-directed to a new file using the below code:
window.location.href=pui.normalizeURL("DriverMain.html");
And a further validation is done in the script loaded in this page which checks if the user id/password combo is valid.
So, what I am trying to do is, to re-direct the user back to index.html (the sign-in form) if the credentials are incorrect. Hope I am correct.
Re: Redirect to index.html in case of an error
Posted: Wed Oct 07, 2020 10:59 am
by Scott Klement
You understand that reloading the index.html will reinitialize everything, killing your profound ui session, and so forth? This is not normally done in a single-page application framework such as Profound UI.
Assuming you started from index.html in the first place, an easy way to reload it would be to do this:
Re: Redirect to index.html in case of an error
Posted: Wed Oct 07, 2020 11:03 am
by Theju112
In this scenario, the index.html page is the starting point of the app.
Below is from the config.xml.
<content src="index.html" />
This runs a script appLogin.js which renders the sign-in form to the user. The code has been written in such a way that if the user enters a non blank user id and password, user would be re-directed to a new file using the below code:
window.location.href=pui.normalizeURL("DriverMain.html");
And a further validation is done in the script loaded in this page which checks if the user id/password combo is valid.
So, what I am trying to do is, to re-direct the user back to index.html (the sign-in form) if the credentials are incorrect. Hope I make sense.
Re: Redirect to index.html in case of an error
Posted: Wed Oct 07, 2020 12:11 pm
by Theju112
Scott Klement wrote:You understand that reloading the index.html will reinitialize everything, killing your profound ui session, and so forth? This is not normally done in a single-page application framework such as Profound UI.
Assuming you started from index.html in the first place, an easy way to reload it would be to do this:
Hi Scott,
I started from index.html but when this validation occurs, I am in another page, DriverMain.html. I tried using window.location.reload(true); but seems it is reloading the drivermain.html page itself and not going back to index.html
Re: Redirect to index.html in case of an error
Posted: Wed Oct 07, 2020 2:00 pm
by Scott Klement
So is it as simple as this?
Re: Redirect to index.html in case of an error
Posted: Thu Oct 08, 2020 3:51 am
by Theju112
Works like a gem.. thanks scott!