Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I have an javascript to redirect to another page after countdown 10 seconds, but it doesn't work. Can anyone help to fix the problem?
<body>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type ="text/javascript" src ="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var number = 10;
var url = 'http://localhost/rms/index.php/';
function countdown() {
setTimeout(countdown,1000);
$('#title1').html("Redirecting in " + number + " seconds");
number --;
if(number<0) {
window.location = url;
number = 0;
}
}
countdown();
});
</script>
</head>
<body>
<div id="title1"></div>
</body>
As everybody wrote in the comments, it should work. Try to replace
<script type ="text/javascript" src ="jquery.js"></script>
with this:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script>
In this case you don't have to worry about your jquery.js file, which could be missing or corrupted.
I have one note to your code. Are you aware of that you call window.location = url; two times?
If its just a regular countdown with redirect I will put the setTimeout call in if statement which will prevent calling it twice.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
Hello,
I downloaded electron and installed it on webstorm in order to learn it. I also installed Jquery using the terminal and including in my scripts but jquery isn't working but it is recognized in my code (I haven't got any error).
My code :
const remote = require('electron').remote;
let window = remote.getCurrentWindow();
function exitGame() {
alert("test");
$('exit').click(() => {
alert("closing");
window.close();
})
}
exitGame();
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Electron Test</title>
<!-- RESET CSS -->
<link rel="stylesheet" type="text/css" href="css/reset.css">
<!-- ADDING CSS -->
<link rel="stylesheet" type="text/css" href="css/main_menu.css">
</head>
<body>
<div id="exit">Leave the game</div>
<!-- ADDING JAVASCRIPT -->
<script>
// You can also require other files to run in this process
require('./renderer.js');
require('./js/jquery.min.js');
require('./js/main_menu.js');
</script>
</body>
</html>
The jQuery alert is working but the click isn't.
Even if I replace the "exit" id by "body" it's not working...
Can you tell me what's wrong ?
Thank you very much, best regards.
exit is an id and not some element. So you need to use # before it.
$('#exit').click(() => {
alert("closing");
window.close();
})
Better way to check jQuer is wokring or not could be:
if(!jQuery)
{
alert("Not working!");
}
Alright, made it working by editing the tag with the code requiere jQuery.
Before Electron's base script tag, I added a tag with my jQuery. It seems that it wasn't loaded
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I want to start a timer at first keypress (on the ) and it should count down till 0. The catch is that once it is started it should not stop until it has reached 0 nor it should be affected by subsequent key presses.
Thank you! :)
<html>
<head>
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<h1 align="center"></h1>
<script>
var time=10;
var timer;
$('body').keypress(function() {
timer=setInterval(function(){
if(time<=0)
clearInterval(timer);
$('h1').html(time);
time--;
},1000)
$(this).unbind('keypress');
});
</script>
</body>
</html>
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
Well here's my Function as well as my basic HTML page. I have created it with an alert script but it does not run.
Here's the function (Something.js)
function crypto_encrypt(text) { //This is for JS
var keyBase64 = CryptoJS.enc.Base64.parse("ITU2NjNhI0tOc2FmZExOTQ==");
var iv = CryptoJS.enc.Base64.parse('AAAAAAAAAAAAAAAAAAAAAA==');
var encrypted = CryptoJS.AES.encrypt(CryptoJS.enc.Utf8.parse(text), keyBase64,
{
keySize: 128 / 8,
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
});
// Returns a Base64 encoded string.
return encrypted;
}
Now I have this HTML but when i load it it does not give an alert
(Test.php) <-----does it have something to do with the naming when I saved it in sublime?
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script type='text/javascript' src='./jquery.soap.js'></script>
<!--<script type='text/javascript' src='./soapclient.js'></script>-->
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"> </script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc- base64-min.js"></script>
<script type='text/javascript' src='./HCSConnect.js'></script>
</head>
<body>
<script language="JavaScript">
var encryptedname = crypto_encrypt('Patrick');
alert(encryptedname)
</script>
</body>
</html>
There are some spaces in the url for this script:
http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc- base64-min.js
That is the reason you get a 404 (not found). The entire following script fails. Change it to:
http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-base64-min.js
See this jsfiddle.
You are missing a ; after alert() statement.
Remove spaces from source URL:
<script type="text/javascript" src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-base64-min.js"
Also, it is advisable to use type="text/javascript"
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I will send my clients the link for the app in the following format
http://goo.gl.com/downloadtheapp (or whatever)
I want this file be somewhere on my server that includes java script code that checks what is the device type and redirects to the convenient store. that is, google play if the device was android based and appstore if the device was ios based.
till now I tried this, but it does not work.
<html>
<head>
<script type="text/javascript">
$(document).ready(function ()
{
if(navigator.userAgent.toLowerCase().indexOf("android") > -1)
{
window.location.href = 'http://play.google.com/store/apps/details?id=com.truecaller&hl=en';
}
if(navigator.userAgent.toLowerCase().indexOf("iphone") > -1)
{
window.location.href = 'http://itunes.apple.com/lb/app/truecaller-caller-id-number/id448142450?mt=8';
}
}
</javascript>
</head>
<body>
</body>
</html>
The problem is with your script tag and you are missing );
And by the way, did you import jQuery?
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script>
$(document).ready(function (){
if(navigator.userAgent.toLowerCase().indexOf("android") > -1){
window.location.href = 'http://play.google.com/store/apps/details?id=com.truecaller&hl=en';
}
if(navigator.userAgent.toLowerCase().indexOf("iphone") > -1){
window.location.href = 'http://itunes.apple.com/lb/app/truecaller-caller-id-number/id448142450?mt=8';
}
});
</script>
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
My html is like this:
<!DOCTYPE html>
<html>
<head>
<title>
Event Handling
</title>
</head>
<body>
<h1> This is the chapter in which I am handling Events.The site you should visit is: </h1>
<b>here<b>
<script src="events.js"></src>
</body>
</html>
The javascript is like this:
var link = document.getElementsByTagName("a")[0];
link.onclick = MyEventHandler;
function MyEventHandler()
{
alert("ouch!");
return false;
}
It is not working, but using inling event handler I am doing it successfully. Please helop me.
You need to assign the event handler function, not the return value of calling that function.
link.onclick = MyEventHandler;
(Also note that you need to use the end tag </script> not </src>.)