I am struggling with Back button link.
For back button, I am using Back to go to the previous page. This works absolutely fine in Chrome but not in IE and Firefox. In IE it stays on the same page and in Firefox I get "Page Expired" message.
I have a hint of a problem but i don't know the solution.
So my trace of URL is :
/xyz/client/auth/createIDForm.do which redirects xyz/client/pub/redirectByURL.jsp?nextURL=/auth/setQnAForm.do
Now the landing page is xyz/client/auth/setQnAForm.do however the back button on this page is having problem like I have mentioned above.
I think its going back to rediretByURL.jsp?nextURL=/auth/setQnAForm.do and refreshes the same page however in Chrome.I think the back page is loading from cache.
Please help me in this.
try to use this one
<button onclick="goBack()">previous page</button>
<script>
function goBack() {
if(navigator.userAgent.indexOf("Chrome") != -1 )
{
window.history.go(-1);
}
else if(navigator.userAgent.indexOf("Safari") != -1)
{
window.history.go(-1);
}
else if(navigator.userAgent.indexOf("Firefox") != -1 )
{
window.history.go(-1);
}
else if((navigator.userAgent.indexOf("MSIE") != -1 ) || (!!document.documentMode == true )) //IF IE > 10
{
window.location.href="yourPageLink";
}
}
</script>
Related
I have a web page that checks for a cookie on page load and if the cookie does not exist the user is redirected to a certain log in page based on conditions. I am trying to add another condition to the cookie check but it is creating an infinite loop. Is there a way to allow another condition?
function checkCookie() {
var current_url = window.location.pathname;
var logInCookie = _siteNS.Utils.readCookie('x-access');
if (!logInCookie) {
if (
window.location.toString().includes('-fr') &&
current_url != '/landing-fr.html'
) {
window.location.replace('/landing-fr.html');
} else if (
window.location.href.indexOf('-fr') === -1 &&
current_url != '/landing.html'
) {
window.location.replace('/landing.html');
} else if (
window.location.href.indexOf('-fr') === -1 && *=== This is creating infinite loop===*
current_url === '/Important_Safety_Information.html'
) {
window.location.replace('/Important_Safety_Information.html');
}
}
}
The problem is that you're redirecting the user back to the page they are already on. When the user loads that same page, it's going to invoke that same logic again and redirect the user again... to the same page.
From a comment on the question above:
What I want to do is if the user goes to '/Important_Safety_Information.html' stay there and do not redirect
If you don't want to redirect the user then... don't redirect the user. Just remove that last else if block entirely since you don't want to perform that operation. Or, at worst, if you need to include this condition in an ongoing list of conditions then simply keep the block empty:
else if (
window.location.href.indexOf('-fr') === -1 &&
current_url === '/Important_Safety_Information.html'
) { /* do nothing */ }
Is it possible to disable a piece of jQuery for Safari only? Having issues getting it to work correctly due to Safari loading the cached page when you click "back" so i just want to disable it completely in Safari only.
jQuery(".hometext").click(function() {
jQuery(this).toggleClass("slide");
jQuery(".hometext").toggleClass("active");
jQuery("#header-elementor").toggleClass("active");
})
})
You can do something below.
if (
navigator.userAgent.indexOf('Safari') != -1 &&
navigator.userAgent.indexOf('Chrome') == -1 &&
navigator.userAgent.indexOf('CriOS/') == -1
){
console.log('applied code to only safari');
} else {
console.log('applied code except safari');
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
I'm trying to hide a form only if it's on the root site, or on the specific hash https://www.example.com/#uno. My code below is causing the form is not show on all the subpages (/#dos, /#tres, etc). Can someone help me understand what is happening?
$(function(){
if (location.hash == "" || location.hash == "#uno"){
$("#form").hide();
} else {
$("#form").show();
};
}());
This is because you hide the form once, but you don't make it reappear until you reload the page. (You only check the hash once, when loading the entire page, not when the hash changes.
function showHideForm() {
if (location.hash == "" || location.hash == "#uno"){
$("#form").hide();
} else {
$("#form").show();
};
}
window.onhashchange = showHideForm;
I am running into a problem with re-directing to my mobile version. I do not have the programming skills to accomplish this. I am stuck.
Here is the code I have below, but first here is the logic I WANT to accomplish:
When a mobile user visits a mobile version is served by default.
If they click the 'View Full Site' then it switches and stays on the full site UNTIL and only IF they click the View Mobile Version (footer) and then it stays on the MOBILE version, unless they click on 'View Full Site' again.
That is it but I cannot get it to work.
Here is the code that I placed in the header:
<script type="text/javascript">
<!--
var fullSiteCookie = readCookie('fullsite');
if ( fullSiteCookie !='t' ) {
if (screen.width <= 600) {
window.location = "/m/mobile.html";
}
if ( (navigator.userAgent.indexOf('Android') != -1) ) {
document.location = "/m/mobile.html";
}
if ( (navigator.userAgent.indexOf('iphone') != -1) ) {
document.location = "/m/mobile.html";
}
else
document.location="/";
}
//-->
</script>
Then the hyperlink on the full site is:
View Mobile Site</span>
Likewise the mobile site has it's own link:
FULL SITE VERSION
PROBLEM: I can never get the site to go (the first time) over to the mobile version. It only goes to the full desktop version. That is a show-stopper. It MUST be able to automatically send visitors to the mobile site if they are visiting the site on a mobile device. The should not have to click anything.
Any ideas? I am just not going to be able to figure this out, without help. Of course this is something I need yesterday.
Your elseis placed IN the if so it triggers only on the NOT iPhone condition.
Try this:
if ( fullSiteCookie !='t' ) {
if (fullSiteCookie =='m' || screen.width <= 600 || navigator.userAgent.indexOf('Android') != -1 || navigator.userAgent.indexOf('iphone') != -1) {
window.location = "/m/mobile.html";
} else {
// not mobile or forced mobile
document.location = "/";
}
} else {
// forced Normal
document.location = "/";
}
Similar to #Loyalty Tech's suggestion, but I have some to add.
var fullSiteCookie = readCookie('fullsite');
/* Verify that "fullSiteCookie" is a valid value.
Are you sure the cookie is set the first time?
*/
if ( fullSiteCookie !='t' &&
(screen.width <= 600 ||
navigator.userAgent.indexOf('Android') != -1 ||
/* Fix case of "iphone" to "iPhone" */
navigator.userAgent.indexOf('iPhone') != -1)){
window.location = "/m/mobile.html";
} else {
window.location = "/";
}
I'm currently using this code:
var domains = ["domain.net", "domain.com", "domain.info"];
if (domains.indexOf(document.location.hostname) == -1 && document.cookie.indexOf('redirected=1') == -1)
{
window.top.location="http://domain.net";
document.cookie = "redirected=1";
alert("Redirecting to our main website");
}
else if (domains.indexOf(document.location.hostname) == 1)
{
document.cookie = "redirected=1";
}
alert("Thanks for joining our main website");
if i move the second alert over "}" it will not give any alert, and when i leave it as it is i will get sequential alerts starting with 1st alert and then second alert, then when page redirects i will get second alert again.
is there a way to fix this ?
Thanks in advance