Disable piece of jQuery for Safari only - javascript

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>

Related

mouseenter/mouseover event in Chrome not working

This is the code I'm using right now:
signup.onmouseover = function() {
if(pass.value == passcheck.value && pass.value.length >= 6 && pass.value.length <= 60 && passcheck.value.length >= 6 && passcheck.value.length <= 60 && username.value.length >= 3 && username.value.length <= 20){
signup.removeAttribute("disabled");
} else {
signup.setAttribute("disabled", "true");
alert("Different passwords or length of username or password incorrect, check again!");
}
}
In Firefox it works, in Chrome and Safari it doesn't work at the moment. Does anyone know why?
I also used mouseenter event which doesn't work in Chrome and Safari.
EDIT
There's no error displayed when I move the mouse over the signup element. Just nothing happens when I do that which I don't understand.
mouseover works just fine in Chrome (https://developer.mozilla.org/en-US/docs/Web/API/Element/mouseover_event)
Make sure, it's mouseover and not onmouseover.
document.querySelector("button").addEventListener("mouseover", function () {
console.log("over");
});
<button>Button</button>

Make a certain div show when the user's browser is detected

(UPDATED)
I am trying to make a certain div show when the user's browser is detected. I found the code online and am not sure if it even works or how to put a div in the certain browser sections of the code.
<script>
function BrowserDetection() {
if(!navigator || !navigator.userAgent) {
// Insert condition for old browsers
}
else if (navigator.userAgent.search("MSIE") >= 0) {
// Insert conditional IE code here
}
else if (navigator.userAgent.search("Chrome") >= 0) {
alert('code');
}
else if (navigator.userAgent.search("Firefox") >= 0) {
// Insert conditional Firefox Code here
}
//Check if browser is Safari
else if (navigator.userAgent.search("Safari") >= 0 && navigator.userAgent.search("Chrome") < 0) {
// Insert conditional Safari code here
}
//Check if browser is Opera
else if (navigator.userAgent.search("Opera") >= 0) {
// Insert conditional Opera code here
}
}
</script>
This one does not seem to work. Would anyone know where I could possibly find a working code. Thank you very much..
basically, there is a window.navigator object in browsers that gives information about the browser.
The above code should be updated to check if this navigator object exists before trying to access the userAgent.
ALSO, &GT; is not a valid comparison operator, replace it with >=
function BrowserDetection() {
if(!navigator || !navigator.userAgent) {
// Insert condition for old browsers
}
else if (navigator.userAgent.search("MSIE") >= 0) {
// Insert conditional IE code here
}
else if (navigator.userAgent.search("Chrome") >= 0) {
// Insert conditional Chrome code here
}
else if (navigator.userAgent.search("Firefox") >= 0) {
// Insert conditional Firefox Code here
}
//Check if browser is Safari
else if (navigator.userAgent.search("Safari") >= 0 && navigator.userAgent.search("Chrome") < 0) {
// Insert conditional Safari code here
}
//Check if browser is Opera
else if (navigator.userAgent.search("Opera") >= 0) {
// Insert conditional Opera code here
}
}
Inspect it using F12 and check if you can see that div in your sources code. Then add debugger to it and try checking your functionality.

Back Button Issue

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>

How do I redirect to mobile, but let the user switch from then on?

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 = "/";
}

problem with keypress (in jquery) with IE

problem with keypress (in jquery) with IE
$(document).keypress(function(key) {
if (key.which == 99 && key.metaKey == true) {
alert("Don't Copy");
return false;
}
});
It doesn't work !
How can I fix it ?
I think you want to check the status of ctrlKey to block Ctrl + C:
$(document).keydown(function(key) {
if (key.which == 67 && key.ctrlKey) {
alert("Don't Copy");
return false;
}
});
It does work on all major browsers (FF4b7, IE 8), but not entirely correct in Chrome 8: although the alert pops up, the copy-to-clipboard behaviour is not suppressed.
That said, if you want to prevent the user from copying your texts to the clipboard, I'll have to disappoint you: someone can simply use the (context) menu option or view your page's source. There's nothing that you can do about that.
why keypress?
$('*').bind('copy',function(key) {
alert("Don't Copy");
return false;
});

Categories

Resources