I need to use <meta http-equiv="REFRESH"> to display the current time as it changes.
This is what i tried:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="refresh" content="1">
<script type="text/javascript">
function change_time()
{
var d = new Date();
var curr_hour = d.getHours();
var curr_min = d.getMinutes();
var curr_sec = d.getSeconds();
if(curr_hour > 12)
curr_hour = curr_hour - 12;
document.getElementById('time').innerHTML = curr_hour+':'+curr_min+':'+curr_sec;
}
change_time();
</script>
</head>
<body>
<table>
<tr>
<td>Current time is :</td>
<td id="time"></td>
<tr>
</table>
</body>
</html>
The page refreshes itself every second but it doesn't not show the functions value.
You forgot to call your Javascript function when you have loaded the page. You can achieve that by using the onload attribute on the body node:
<body onload="change_time()">
See also: How do I call a JavaScript function on page load?
Use this
<body onload="change_time()">
Remove change_time(); line just before closing </script> tag.
Edit:
You have forgot to call your javascript method on load/refresh of page.
To do so - use onload() event of body tag in html.
Related
in my college the webpage we retrieve our semester results by typing the name and the student ID.
I am learning web scraping right now for projects, does scrapy or BeatifulSoup provide a solution for retrieving for example 100 results at one go?
you can view it's content here : view-source:http://app1.helwan.edu.eg/Commerce/HasasnUpMlist.asp
it uses a code such as follows:
<html>
<head>
<meta http-equiv="Content-Language" content="ar-eg">
<title></title>
<link href="natiga.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<meta name="generator" content="Hassan_kandeell#yahoo.com" />
</head>
<body>
<script type="text/javascript">
<!--
var EW_DATE_SEPARATOR; // Default date separator
EW_DATE_SEPARATOR = "/";
if (EW_DATE_SEPARATOR == '') EW_DATE_SEPARATOR = '/';
EW_UPLOAD_ALLOWED_FILE_EXT = "gif,jpg,jpeg,bmp,png,doc,xls,pdf,zip"; // Allowed upload file extension
var EW_FIELD_SEP = ', '; // Default field separator
// Ajax settings
EW_LOOKUP_FILE_NAME = "ewlookup61.asp"; // lookup file name
EW_ADD_OPTION_FILE_NAME = "ewaddopt61.asp"; // add option file name
// Auto suggest settings
var EW_AST_SELECT_LIST_ITEM = 0;
var EW_AST_TEXT_BOX_ID;
var EW_AST_CANCEL_SUBMIT;
var EW_AST_OLD_TEXT_BOX_VALUE = "";
var EW_AST_MAX_NEW_VALUE_LENGTH = 5; // Only get data if value length <= this setting
// Multipage settings
var ew_PageIndex = 0;
var ew_MaxPageIndex = 0;
var ew_MinPageIndex = 0;
var EW_TABLE_CLASSNAME = "ewTable"; // Note: changed the class name as needed
var ew_MultiPageElements = new Array();
//-->
</script>
<script type="text/javascript" src="ew61.js"></script>
<script type="text/javascript" src="userfn61.js"></script>
<script language="JavaScript" type="text/javascript">
<!--
// Write your client script here, no need to add script tags.
// To include another .js script, use:
// ew_ClientScriptInclude("my_javascript.js");
//-->
</script>
<div align="center">
<table border="0" width="1001" dir="rtl">
<tr>
<td width="995" colspan="2">
<p align="center">
<img border="0" src="Start.JPG" width="995" height="198"></td>
</tr>
<tr>
<td bgcolor="#AC8601" width="737">
<p align="center"> </td>
<td bgcolor="#800000" width="254">
<p align="center"><font size="5" color="#FFFFFF"><b>نتائج كلية
التجارة وإدارة الأعمال</b></font></td>
</tr>
</table>
</div>
<script type="text/javascript">
<!--
var EW_PAGE_ID = "list"; // Page id
//-->
</script>
<script type="text/javascript">
<!--
function ew_ValidateForm2(fobj) {
var infix = "";
for (var i=0;i<fobj.elements.length;i++) {
var elem = fobj.elements[i];
if (elem.name.substring(0,2) == "s_" || elem.name.substring(0,3) == "sv_")
elem.value = "";
}
return true;
}
//-->
I am just asking for educational purposes, I want to make a project for my colleagues because the traffic in the website is very high and it takes hours to get even one result.
Thanks.
Definitely, you will be able to scrap all the results in one go using javascript, scrapy, BeautifulSoup, etc... if all the records are visible on the same page itself.
If the webpage displays results through pagination it should visit all the pages and scrap accordingly.
Hope this helps.
I have a list of links that I have in my spreadsheet.
I created a button. Now I select the link and I click the download button. I want it to start download right away the document from the link.
This is what I have right now:
function RDownload() {
var RConSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("LookUp");
var LNumber = RConSheet.getRange("C2").getValue;
var RLinkID = RConSheet.getRange("J4").getValue();
var RLink= "https://drive.google.com/uc?export=download&id="+RLinkID;
return RLink;;
};
/* download RCon */
function test(){
var form = HtmlService.createHtmlOutputFromFile('DownloadR');
SpreadsheetApp.getUi().showModalDialog(form, "Downloading");
}
I don't know how to get value from RLink and put it in the html form.
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<a href='here I want to have a value from RLink' target='_blank'>Download</a>
</body>
</html>
Description
I didn't need to change your Code.gs but I've modified your HTML to include a call to the server to get RLink using google.script.run.withSuccessHandler().
HTML
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<a id="rlink" href='here I want to have a value from RLink' target='_blank'>Download</a>
<script>
(function () {
google.script.run.withSuccessHandler( function (rlink) {
alert(rlink);
document.getElementById("rlink").href = rlink;
}).RDownload();
})();
</script>
</body>
</html>
References
https://developers.google.com/apps-script/guides/html/reference/run#withSuccessHandler(Function)
I am trying to learn JQuery running sample codes dealing with SetInterval or Settimeout I find on the Internet, but they won't run or work. For instance, I have the following simple code, but it won't run or even give me error message.
<!DOCTYPE html>
<html>
<head>
<title>testing</title>
<script type="text/javascript">
$(document).ready(function(){
setInterval(function() {
var number = 1 + Math.floor(Math.random() * 333);
$('#here').load(number);
},
1000);
});
</script>
</head>
<body>
<div id="here">dynamic content ?</div>
</body>
</html>
You first missed to add jquery library and second you should use .text() function rather than .load() function.
.load() function should use for ajax method.
One of the essential rules that should keep in mind that always put javascript code at the end of the page and before the end of the body tag
$(document).ready(function() {
setInterval(function() {
var number = 1 + Math.floor(Math.random() * 333);
$('#here').text(number);
}, 1000);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<title>testing</title>
</head>
<body>
<div id="here">dynamic content ?</div>
</body>
</html>
I have been looking for a solution for this for a long time and I just could not find what I was looking for. I have made a code that is an automatic traffic light and it loops through. How can I change it so when I click it goes through the sequence and stops when it gets back to Red?
<!DOCTYPE html>
<html>
<head>
<title>Demo</title>
</head>
<body onload="startTime();">
<img id="img1" />
<script>
var imgArray = new Array("Red.jpg","RedA.jpg","Green.jpg","Amber.jpg");
var imgCount = 0;
function startTime() {
if(imgCount == imgArray.length) {
imgCount = 0;
}
document.getElementById("img1").src = imgArray[imgCount];
imgCount++;
setTimeout("startTime()", 1000);
}
</script>
</body>
</body>
</html>
You just need to change setTimeout function syntax.
setTimeout(function(){
startTime();
},1000);
Check working example
I know a iframe tag can access to parent element with same domain + ports.
However, what if parent and iframe has different domain + port ?
i.e.
parent's domain is http://aaa.com:63342, and iframe domain is http://aaa.com:9080.(Please note that they have different ports)
Both of pages have <meta http-equiv='X-Frame-Options' content='ALLOWAll'> in their headers.
first, parent frame call iframe with form submit. like...
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='X-Frame-Options' content='ALLOWAll'>
<title>ParentWindows with aaa.com:63342</title>
</head>
<body>
<form name='form' method='post' id='form' action=''>
<input type='text' name='greetings' value='Hello from the otherside'>
</form>
<script>
document.form.target = 'iframe';
document.form.action = 'http://aaa.com:9080//inFrame.jsp';
document.form.submit();
</script>
</body>
<iframe src="" name='iframe'></iframe>
</html>
Then a server returns like below in jsp
<%
response.setHeader("X-Frame-Options", "ALLOWAll");
String greetings = request.getParameter("greetings");
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='X-Frame-Options' content='ALLOWAll'>
<title>iframe with aaa.com:9080</title>
</head>
<body>
<div>
greetings message : <%= greetings %>
</div>
</body>
<script>
var div = document.createElement('div');
div.textContent = 'Echo Hello';
parent.document.body.appendChild(div);
</script>
</html>
It is simple version of the situation what I am in. However, when I do like this, browser console shows error like..
Uncaught SecurityError: Blocked a frame with origin "http://localhost:9080" from accessing a frame with origin "http://localhost:63342". Protocols, domains, and ports must match.
Now I am doubting with this method(calling different hosts between iframe and parent) is possible at first place... Is it possible?
How can I make this works?
Thanks a lot
Detour to original frame.
something like...
original page with aaa.com:63342/original.html is
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='X-Frame-Options' content='ALLOWAll'>
<title>ParentWindows with aaa.com:63342</title>
<script>
function setGreetings(greetings){
document.getElementById('greetings').value = greetings;
}
</script>
</head>
<body>
<form name='form' method='post' id='form' action=''>
<input type='text' id='greetings' name='greetings' value='Hello from the otherside'>
</form>
<script>
document.form.target = 'iframe';
document.form.action = 'http://aaa.com:9080//inFrame.jsp';
document.form.submit();
</script>
</body>
<iframe src="" name='iframe'></iframe>
</html>
Then page(jsp) which imported into the original page(inside of iframe) looks like... I can call aaa.com:9080/inFrame.jsp
<%
response.setHeader("X-Frame-Options", "ALLOWAll");
String greetings = request.getParameter("greetings");
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='X-Frame-Options' content='ALLOWAll'>
<title>iframe with aaa.com:9080</title>
</head>
<body>
<div>
greetings message : <%= greetings %>
</div>
<iframe id='iframe' src="http://localhost:63342/third.html?greetings=<%= greetings %>"></iframe>
</body>
</html>
This is the third frame aaa.com:63342/third.html, final
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='X-Frame-Options' content='ALLOWALL'>
<title>ACCESS TO TOP FRAME on localhost:63342</title>
</head>
<body>
<script>
function setGrandfather(){
var greetings = getParams()['greetings'];
window.top.setGreetings(greetings);
}
//parsing parameters
function getParams() {
var param = new Array();
var url = decodeURIComponent(location.href);
url = decodeURIComponent(url);
var params;
params = url.substring( url.indexOf('?')+1, url.length );
params = params.split("&");
var size = params.length;
var key, value;
for(var i=0 ; i < size ; i++) {
key = params[i].split("=")[0];
value = params[i].split("=")[1];
param[key] = value;
}
return param;
}
</script>
</body>
</html>
What happens here
the original page has iframe which has different domain
the second page(iframed in the original page) also has an iframe which has same origin with original page
the second page will send data to its iframe(the third page) with post/get. I wish it could access other frame element via parent.document or iframe.contentDocument.document, but these will be blocked by SAMEORIGIN policy.
In third page you can access functions and elements of the original frame since they have same origin(domain + ports).
CAUTION
frames can not communicate directly
only those pages has common url, possible to set sub domain via document.domain