how to make an alert pop up before my script [closed] - javascript

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 2 years ago.
Improve this question
I'm new to js and I was working on something where this thing makes a bunch of new tabs, but when the code is run, the alert pops up when each tab is opened and on each individual tab.
here's the code
<script>
alert('something')
setInterval(function() {
var w = window.open();
w.document.write(document.documentElement.outerHTML||document.document
Element.innerHTML);
}, );
</script>
pls be nice I'm new

What about this one
<!DOCTYPE html>
<html>
<body>
<p>Click the button to open a new browser window.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
alert("Hi there");
window.open("https://www.w3schools.com");
}
</script>
</body>
</html>

Related

How to change opacity of a div on button click using JS? [closed]

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 10 months ago.
Improve this question
I am trying to add a script to my HTML file that changes the opacity of a div when a button is clicked.
This is the HTML file
This is the CSS file
This is my function
Essentially what I'm trying to achieve is the div that is currently set to 0 opacity, will be change to 1 opacity on the click of the button. Currently this is not working, and I am relatively new to incorporating JS in and HTML file. Any tips would be greatly appreciated.
Here's a simple example using JavaScript embedded in HTML. Make sure you're using an event listener that listens for the click of your button.
<!DOCTYPE html>
<html>
<head>
<title>About Me</title>
</head>
<body>
<h1 style="opacity: 0;">About Me</h1>
<button>
Show
</button>
<script>
var button = document.querySelector('button');
button.addEventListener('click', function() {
var h1 = document.querySelector('h1');
h1.style.opacity = 1;
});
</script>
</body>
</html>

collapse and expand button in a google site [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I'm working on a Google site as I though it was easier...But I'm having some troubles with it. I'd like to create a button that expand and collapsea block of text. I've tried some different options but I didn't get it. Does anyone know how to do it?
Thanks a lot
EDIT: Something like this:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("p").toggle();
});
});
</script>
</head>
<body>
<button>Toggle between hiding and showing the paragraphs</button>
<p>This is a paragraph with little content.</p>
<p>This is another small paragraph.</p>
</body>
</html>
http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_toggle
For example, if you can use JavaScript, you can set the style to "display:none;" or "display:block;" by clicking a button.
<div id="ThisTextWillBeHidden">This text needs to be hidden</div>
<button type="button"
onclick="document.getElementById("ThisTextWillBeHidden").style.display='none';">
Click me to hide!
</button>
<button type="button"
onclick="document.getElementById("ThisTextWillBeHidden").style.display='block';">
Click me to show!
</button>
I assume Google Sites does not support scripts, so you will need to save this code somewhere else, like on your hosting or in a file storage service, and call it like this:
<iframe src="location of the file containing your code.html"></iframe>

Keypress Event - Javascript/Jquery [closed]

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>

both program have nearly same code but output is different [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
<!DOCTYPE html>
<html>
<body>
<h1>My First Web Page</h1>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction()
{
document.write("Oops! The document disappeared!");
}
</script>
</body>
</html>
The above code is showing output like below
My First Web Page
Try it
After clicking Try it button I got output like below
Oops! The document disappeared!
In internet i found the reason for disappear is If I execute document.write after the document has finished loading, the entire HTML page will be overwritten.
but my doubt is when document has finished loadind...........i am not gettimg it.
Then I modified the above code like below
<!DOCTYPE html>
<html>
<body>
<h1>My First Web Page</h1>
<button onclick="myFunction()">Try it</button>
<script>
function myfunction()
{
document.write("My First JavaScript");
}
</script>
</body>
</html>
but the above code is showing output like below
My First Web Page
Try it
After pressing Try it button it is not giving any output.I don't know why these 2 program are working like this.help me..................
Second one is failing because you have a small f in myfunction and call it with a big F
In Chrome, if you open Developer tools ( Cntrl-Shift-J ) and go to the console it will show you the javascript error.
The problem in the second page is that you are calling a function called myFunction.
But the function that you have is called myfunction, the F is in Uppercase.
so the javascript error is:
Uncaught ReferenceError: myFunction is not defined
JavaScript is case sensitive. You define
myfunction
But call
myFunction
Note the F.
In your second function, myfunction, F should be CAPS or at onclick=myFunction() F should be small. Check your console window. No output is because of javascript errors

Error about dynamic countdown redirect [closed]

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.

Categories