i want to open several tabs when someone clicks this button.but my current code just opens the first.by the way this is a repost since the previous 1 had a lot of typos that i corrected
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button id="hi" type="submit" onclick="redirect()">button</button>
</body>
</html>
<script>
function redirect(){
var window1 = 'https://google.com';
window.open(window1, '_blank');
var window2 = "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
window.open(window2, '_blank');
var window3 = "https://www.youtube.com/shorts/AlvXHz2pUL4"
window.open(window3, '_blank');
var window4 = "https://www.youtube.com/watch?v=J2GVKuYoIww"
window.open(window4, '_blank');
var window5 = "https://www.youtube.com/watch?v=1Z6CHioIn3s&list=RDMMYrJqDCaeSZg&index=20"
window.open(window5, '_blank');
var window6 = "https://www.youtube.com/watch?v=KbNL9ZyB49c&list=RDKbNL9ZyB49c&start_radio=1&rv=KbNL9ZyB49c&t=32&t=32"
window.open(window6, '_blank');
var window7 = "https://www.youtube.com/watch?v=fB8TyLTD7EE&list=RDKbNL9ZyB49c&index=3"
window.open(window7, '_blank');
var window8 = "https://www.youtube.com/watch?v=Zasx9hjo4WY&list=RDKbNL9ZyB49c&index=8"
window.open(window8, '_blank');
var window9 = "https://www.youtube.com/watch?v=r6zIGXun57U&list=RDKbNL9ZyB49c&index=7"
window.open(window9, '_blank');
var window10 = "https://www.youtube.com/watch?v=v7HAVTyvLqI&list=RDKbNL9ZyB49c&index=8"
window.open(window10,'_blank');
}
</script>
I want to make a program which adds a textbox every time you click a button. Here's my code:
window.onload = function () { linelist = document.getElementById("linelist"); };
function AddLine() {
linelist.innerHTML += "<div class=\"normallink\"><input type=\"text\"><button class=\"dustbin\"><img src=\"dustbin.png\"></button></div><br />";
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div id="linelist"></div><br />
<button id="addline" onclick="Addline();">+</button>
</body>
</html>
When I run it, it generates an error. Why is this occurring?
You have to define linelist outside the functions first with let or var:
let linelist = null;
window.onload = function () { linelist = document.getElementById("linelist"); };
function AddLine() {
linelist.innerHTML += "<div class=\"normallink\"><input type=\"text\"><button
class=\"dustbin\"><img src=\"dustbin.png\"></button></div><br />";
}
I'm trying to da when it's raining outside that I got "It's raining" on my page. But there is a problem. I allwys get "It's raining" evein when it's sunny. Here's my code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
</head>
<body>
<script>
// Docs at http://simpleweatherjs.com
$(document).ready(function() {
$.simpleWeather({
location: 'Grad Zagreb, Croatia',
woeid: '',
unit: 'c',
success: function(weather) {
html = '<h2><i class="icon-'+weather.code+'"></i> '+weather.temp+'°'+weather.units.temp+'</h2>';
html += '<ul><li>'+weather.city+', '+weather.region+'</li>';
html += '<li class="currently">'+weather.currently+'</li>';
html += '<li>'+weather.wind.direction+' '+weather.wind.speed+' '+weather.units.speed+'</li></ul>';
$("#weather").html(html);
},
error: function(error) {
$("#weather").html('<p>'+error+'</p>');
}
});
if(weather.code == 5 || weather.code == 6 || weather.code == 10 || weather.code == 35){
$("#oprez").html('It's raining!');}
});
(function(e){"use strict";e.extend({simpleWeather:function(t){t=e.extend({location:"",woeid:"2357536",unit:"f",success:function(e){},error:function(e){}},t);var n=new Date;var r="//query.yahooapis.com/v1/public/yql?format=json&rnd="+n.getFullYear()+n.getMonth()+n.getDay()+n.getHours()+"&diagnostics=true&callback=?&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&q=";if(t.location!==""){r+='select * from weather.forecast where woeid in (select woeid from geo.placefinder where text="'+t.location+'" and gflags="R") and u="'+t.unit+'"'}else if(t.woeid!==""){r+="select * from weather.forecast where woeid="+t.woeid+' and u="'+t.unit+'"'}else{t.error("Could not retrieve weather due to an invalid location.");return false}e.getJSON(r,function(n){if(n!==null&&n.query.results!==null&&n.query.results.channel.description!=="Yahoo! Weather Error"){e.each(n.query.results,function(e,n){if(n.constructor.toString().indexOf("Array")!==-1){n=n[0]}var r=["N","NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW","N"];var i=r[Math.round(n.wind.direction/22.5)];if(n.item.condition.temp<80&&n.atmosphere.humidity<40){var s=-42.379+2.04901523*n.item.condition.temp+10.14333127*n.atmosphere.humidity-.22475541*n.item.condition.temp*n.atmosphere.humidity-6.83783*Math.pow(10,-3)*Math.pow(n.item.condition.temp,2)-5.481717*Math.pow(10,-2)*Math.pow(n.atmosphere.humidity,2)+1.22874*Math.pow(10,-3)*Math.pow(n.item.condition.temp,2)*n.atmosphere.humidity+8.5282*Math.pow(10,-4)*n.item.condition.temp*Math.pow(n.atmosphere.humidity,2)-1.99*Math.pow(10,-6)*Math.pow(n.item.condition.temp,2)*Math.pow(n.atmosphere.humidity,2)}else{var s=n.item.condition.temp}if(t.unit==="f"){var o="c";var u=Math.round(5/9*(n.item.condition.temp-32));var a=Math.round(5/9*(n.item.forecast[0].high-32));var f=Math.round(5/9*(n.item.forecast[0].low-32));var l=Math.round(5/9*(n.item.forecast[1].high-32));var c=Math.round(5/9*(n.item.forecast[1].low-32));var h=Math.round(5/9*(n.item.forecast[1].high-32));var p=Math.round(5/9*(n.item.forecast[1].low-32));var d=Math.round(5/9*(n.item.forecast[2].high-32));var v=Math.round(5/9*(n.item.forecast[2].low-32));var m=Math.round(5/9*(n.item.forecast[3].high-32));var g=Math.round(5/9*(n.item.forecast[3].low-32));var y=Math.round(5/9*(n.item.forecast[4].high-32));var b=Math.round(5/9*(n.item.forecast[4].low-32))}else{var o="f";var u=Math.round(9/5*n.item.condition.temp+32);var a=Math.round(9/5*n.item.forecast[0].high+32);var f=Math.round(9/5*n.item.forecast[0].low+32);var l=Math.round(5/9*(n.item.forecast[1].high+32));var c=Math.round(5/9*(n.item.forecast[1].low+32));var h=Math.round(5/9*(n.item.forecast[1].high+32));var p=Math.round(5/9*(n.item.forecast[1].low+32));var d=Math.round(5/9*(n.item.forecast[2].high+32));var v=Math.round(5/9*(n.item.forecast[2].low+32));var m=Math.round(5/9*(n.item.forecast[3].high+32));var g=Math.round(5/9*(n.item.forecast[3].low+32));var y=Math.round(5/9*(n.item.forecast[4].high+32));var b=Math.round(5/9*(n.item.forecast[4].low+32))}var w={title:n.item.title,temp:n.item.condition.temp,tempAlt:u,code:n.item.condition.code,todayCode:n.item.forecast[0].code,units:{temp:n.units.temperature,distance:n.units.distance,pressure:n.units.pressure,speed:n.units.speed,tempAlt:o},currently:n.item.condition.text,high:n.item.forecast[0].high,highAlt:a,low:n.item.forecast[0].low,lowAlt:f,forecast:n.item.forecast[0].text,wind:{chill:n.wind.chill,direction:i,speed:n.wind.speed},humidity:n.atmosphere.humidity,heatindex:s,pressure:n.atmosphere.pressure,rising:n.atmosphere.rising,visibility:n.atmosphere.visibility,sunrise:n.astronomy.sunrise,sunset:n.astronomy.sunset,description:n.item.description,thumbnail:"//l.yimg.com/a/i/us/nws/weather/gr/"+n.item.condition.code+"ds.png",image:"//l.yimg.com/a/i/us/nws/weather/gr/"+n.item.condition.code+"d.png",tomorrow:{high:n.item.forecast[1].high,highAlt:l,low:n.item.forecast[1].low,lowAlt:c,forecast:n.item.forecast[1].text,code:n.item.forecast[1].code,date:n.item.forecast[1].date,day:n.item.forecast[1].day,image:"//l.yimg.com/a/i/us/nws/weather/gr/"+n.item.forecast[1].code+"d.png"},forecast
s:{one:{high:n.item.forecast[1].high,highAlt:h,low:n.item.forecast[1].low,lowAlt:p,forecast:n.item.forecast[1].text,code:n.item.forecast[1].code,date:n.item.forecast[1].date,day:n.item.forecast[1].day,image:"//l.yimg.com/a/i/us/nws/weather/gr/"+n.item.forecast[1].code+"d.png"},two:{high:n.item.forecast[2].high,highAlt:d,low:n.item.forecast[2].low,lowAlt:v,forecast:n.item.forecast[2].text,code:n.item.forecast[2].code,date:n.item.forecast[2].date,day:n.item.forecast[2].day,image:"//l.yimg.com/a/i/us/nws/weather/gr/"+n.item.forecast[2].code+"d.png"},three:{high:n.item.forecast[3].high,highAlt:m,low:n.item.forecast[3].low,lowAlt:g,forecast:n.item.forecast[3].text,code:n.item.forecast[3].code,date:n.item.forecast[3].date,day:n.item.forecast[3].day,image:"//l.yimg.com/a/i/us/nws/weather/gr/"+n.item.forecast[3].code+"d.png"},four:{high:n.item.forecast[4].high,highAlt:y,low:n.item.forecast[4].low,lowAlt:b,forecast:n.item.forecast[4].text,code:n.item.forecast[4].code,date:n.item.forecast[4].date,day:n.item.forecast[4].day,image:"//l.yimg.com/a/i/us/nws/weather/gr/"+n.item.forecast[4].code+"d.png"}},city:n.location.city,country:n.location.country,region:n.location.region,updated:n.item.pubDate,link:n.item.link};t.success(w)})}else{if(n.query.results===null){t.error("An invalid WOEID or location was provided.")}else{t.error("There was an error retrieving the latest weather information. Please try again.")}}});return this}})})(jQuery)
</script>
<div id="weather"></div>
<div id="oprez"></div>
</body>
</html>
Need to add more text,texte,text,text,sorry for this
I have a jsp page which calling a function getModify() in utility.js file. that function performing some action and redirecting some values to next jsp page using window.open()..
am getting the another jsp page as popup window.. how to get the popup window center of the screen.
my jsp:
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script src="script/Utility.js" data-dojo-config="parseOnLoad: true"></script>
</head>
<body>
<div dojotype="dijit.MenuBarItem" id="SearchMenu21" onclick="getModify();" style="font-size:11pt;" title="menuBarItem">
<img class="images" id="SearchMenu21" name="search5.png" onclick="setImgProperty(this.id)" src="images/uploads/search.png" style="height:20px; width:20px;">
Modify
</div>
</body>
</html>
here is my utility.js file:
function getModify(){
var whereCondn = "";
//alert(gbshowgridFlag);
if(dijit.byId('dynamicgridCWPROCESS')){
var selctedItem = dijit.byId('dynamicgridCWPROCESS').selection.getSelected();
if(selctedItem.length){
dojo.forEach(selctedItem, function(selectedItem){
if(selectedItem !== null){
dojo.forEach(dijit.byId('dynamicgridCWPROCESS').store.getAttributes(selectedItem), function(attribute){
var value = dijit.byId('dynamicgridCWPROCESS').store.getValues(selectedItem, attribute);
//alert(value);
if(attribute == "PROCESS_ID"){
whereCondn = whereCondn+attribute+"="+value;
}
//alert("new alert"+whereCondn);
window.open("modifyTask.jsp?MODIFY="+response,'title','height=600px,width=800px,scrollbars=no,sizable=yes,toolbar=no,statusbar=no');
});
}
});
//alert("grid row selected");
}else{
alert("grid row not selected");
}
}
if(gbshowgridFlag==false){
alert("grid not loaded");
}
}
You can also pass "top" and "left" properties for the popup.
window.open("modifyTask.jsp?MODIFY="+response,'title','height=600px,width=800px,scrollbars=no,sizable=yes,toolbar=no,statusbar=no,top='+ topVar + ',left='+leftVar);
Use calculations based on screen.height , and your optimal popup size to decide topVar and leftVar
Please try:
var x = screen.width / 2 - 800 / 2;
var y = screen.height / 2 - 600 / 2;
window.open("modifyTask.jsp?MODIFY="+response,'title' ,'height=600px,width=800px,scrollbars=no,sizable=yes,toolbar=no,statusbar=no,left=' + x + ',top=' + y);
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" type="text/javascript">
function abc()
{
ansArray = ['a'];
document.write('<input type = "button" value = "a">');
document.write('<input type = "button" value = "b">');
var myButton = document.getElementsByTagName("input");
myButton[0].onclick = function() {
if(ansArray[0] == 'a')
myButton[0].style.backgroundColor = "green";
else
myButton[0].style.backgroundColor = "red";
}
myButton[1].onclick = function() {
if(ansArray[0] == 'b')
myButton[1].style.backgroundColor = "green";
else
myButton[1].style.backgroundColor = "red";
}
}
</script>
</head>
<body onload="abc()">
</body>
</html>
This code segment is to change the colour of the two buttons on click event,works fine in chrome and firefox but the onclick functions does not work in IE9. Please help... Thanks in advance
Try calling the function like
(function abc(){
// code here
})();
Also use ; after each function expression, i.e. myButton[0].onclick = function() {...};.
Working here.