unable to display the image in the web page - javascript

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
</HEAD>
<BODY>
<div >
<img border="0" src="img/header.gif" alt="Pulpit rock" width="904" height="128">
<script type="text/javascript">
function detectBrowser() {
// document.write("<img src="C:\Documents and Settings\nawab.a\Desktop\header.gif" border="0">");
//document.write("<br/>");
// document.write("<a href='jre.html','width=100' title='KNOW Your JRE VERSION'>JRE Version</a>");
//Open page in new window
document.write("<br/>");
document.write("<br/>");
var N = navigator.appName;
var UA = navigator.userAgent;
var temp;
var browserVersion = UA.match(/(opera|chrome|safari|firefox|msie)\/?\s*(\.?\d+(\.\d+)*)/i);
if (browserVersion && (temp = UA.match(/version\/([\.\d]+)/i)) != null)
browserVersion[2] = temp[1];
browserVersion = browserVersion ? [browserVersion[1], browserVersion[2]] : [N, navigator.appVersion, '-?'];
document.write("<b>Browser & ContentVerse Software Property</b>")
document.write("<br>");
document.write("Browser Name & Version: " + browserVersion);
document.write("<br>");
document.write("<br>");
// readValue(); // function for get dll details......
}
</script>
</div>
<body onload="javascript:detectBrowser();">
</BODY>
</HTML>
Hi, this code is working fine but unable to display the image....
i want to display the image at the head and then all the information
i think the problem is because of body onload function..
i also tried o display the image in the hyperlink but not working.

Do you run this offline (i mean on your computer) or online, on a web server ?
Just asking because C:\Documents and Settings\nawab.a\Desktop\header.gif is a local path of your computer, not accessible from a remote web server. If this is the case, upload the image on your server and change this path.

Related

Loading text from a txt file depending on day of week

I am using this which loads images depending on day of the week, but I also would like to show text and load it from a file, too. I like to use it as todays menu, so the cook uploads text files, like monday.txt tuesday.txt, and does not need to mess up with coding.
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<META HTTP-EQUIV="refresh" CONTENT="60">
<title>LOUNAS</title>
<style type="text/css">
body {
overflow:hidden;
}
</style>
<script type="text/javascript"><!--
var imlocation = "";
function ImageArray (n) {
this.length = n;
for (var i =1; i <= n; i++) {
this[i] = ' '
}
}
image = new ImageArray(7);
image[0] = 'sunday.jpg';
image[1] = 'monday.jpg';
image[2] = 'tuesday.jpg';
image[3] = 'wednsday.jpg';
image[4] = 'thursday.jpg';
image[5] = 'friday.jpg';
image[6] = 'saturday.jpg';
var currentdate = new Date();
var imagenumber = currentdate.getDay();
document.write('<img src="' + imlocation + image[imagenumber] + '"> style="width:100%;height:100%;" border="0" /');
//--></script></head>
<body bgcolor="#000000">
</body>
</html>
You need to use AJAX request in order to read files from the server.
(If your intention is to display the data to client and not self-display site)
You'll need a server and back-end language like PHP, and then you'll need to make an AJAX request to server depend on the day of the week (meaning which url?) and then display the data.
Second, about what you did, using document.write it's not best way, becuase it clear the page after using and all the data that you had will gone (meaning HTML), and also create element this way dosen't work good in all browsers , you should use createElement instead.
Also, you can use CSS to give style to that element instead of doing it via JavaScript

Script works in Chrome but not in IE or FF

I have the following code that works in chrome however does not work in FF or IE.
The code allows a user to select a text file and re-reads the contents every 10 seconds and updates the PRE tag with the contents of the text file.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Read text file every 10 seconds</title>
<script type="text/javascript">
var currentIntervalId = undefined;
var startOrRestart = function(that) {
if (currentIntervalId !== undefined) clearInterval(currentIntervalId);
readText(that); // For executing immediately
currentIntervalId = setInterval(function() { readText(that); }, 10000);
};
function readText(that){
if(that.files && that.files[0]){
//alert("hello");
var reader = new FileReader();
reader.onload = function (e) {
var contents = e.target.result;//.replace("\r\n","<br/>");
contents = contents.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
document.getElementById('board').innerHTML= contents;
};//end onload()
reader.readAsText(that.files[0]);
}//end if html5 filelist support
}
</script>
</head>
<body>
<input type="file" onchange='startOrRestart(this)' /> <hr />
<pre id="board" contenteditable = "true">
This is where the text from the chosen text file will be loaded.
</pre>
</body>
</html>
Can someone help get this to work in other browsers?
Thanks in advance.
When a file is selected the input has a snapshot of the contents at that point. Local changes on disk don't update the snapshot.
Chrome's implementation appears to break the spec so an example will work only in Chrome.
You can see another question with explanation here

non-cacheable reported in my chrome extension, how to make "cacheable"?

I'm learning to write a chrome extension. I want to inject a real-time time-stamp in current webpage.
I've already finished manifest.json, and html file as background. This html file will call a js file to get current time and display it.
While I do audits in chrome, it says:
The following resources are explicitly non-cacheable. Consider making them cacheable if possible:clock.html, ccc.js, cbd.js.
Here are contents of these three files:
(1) clock.html
<html>
<head>
<script src="ccc.js"></script>
</head>
<font size="7" color='red'>
<body>
<script src="cbd.js"></script>
<div id="showme"></div>
</body>
</font>
</html>
(2) ccc.js
function startTime()
{
var today=new Date();
var h=today.getHours();
var m=today.getMinutes()
var s=today.getSeconds();
var w=today.getMilliseconds()%1000;
h=checkTime(h);
m=checkTime(m);
s=checkTime(s);
w=checkMS(w);
document.getElementById('showme').innerHTML=h+":"+m+":"+s+":"+w;
t=setTimeout('startTime()',1);
}
function checkTime(i)
{
if (i<10)
{i="0" + i;}
return i;
}
function checkMS(i)
{
if((i>9)&&(i<100))
i="0" + i;
else if(i<10)
i="00" + i;
else
{}
return i;
}
(3)cbd.js:
window.addEventListener("load", startTime);
How to make them cacheable...?
Thanks!
Thanks guys, problem solved.
I changed my method, just inject the java script, and it finally works.

Running AJAX locally without a webserver

I have been looking for an answer for this for a month now. I am trying ro run the below script locally and getting "Access Denied" error.
Browser: IE 8
Environment: Locally, Intranet
Kindly share your thoughts on this. Thanks!
<!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>GSDAssist</title>
<script type="text/javascript">
/***********************************************
* Dynamic Ajax Content- � Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
page_request.open('GET', url, true)
page_request.send(null)
}
function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}
function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}
</script>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<title>GSDAssist</title>
</head>
<body style>
<div id="headerBar">
<marquee id="newsTicker" behavior="scroll" direction="left"><h4>Process Updates: Tickets trashed has to be moved to DBSP RECYCLE TICKET Assignment group</h4></marquee>
</div>
<div id="main">
<div style="width:300px; height:80px; margin-left:5px; margin-bottom:10px; float:left;">
<img style="padding:5px; float:left;" src="img/logo.png" width="60" />
<h2 style="float:left; margin-left:5px;">GSDAssist</h2>
</div>
<div style="clear:both; float:left; border-bottom: 1px solid #CCCCCC;">
#
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
<br>
<br>
</div>
<div id="contentarea" style="clear:both; float:left;"><h3>Welcome to GSDAssist,</h3><p><h3>Choose the starting letter of the application to get started!</h3></div>
</div>
</body>
</html>
My thoughts on this are that it's not going to work.
XHR calls are subject to same-domain security policies (CORS is an exception, but that's almost impossible to do without controlling the server, anyway, which requires a server, which is your problem to begin with).
The point is that browsers have set security policies in place, which mean that you must request XHR data from the same domain as your browser is currently on.
file:/// is a completely different protocol than http://, and even so, browser security prevents an HTML page which is served locally from accessing file:// content in an async fashion (to prevent a page from accessing all content on your hard drive, and sending all of your data anywhere in the world).
Just about every web-centric programming language at this point has a quick-start server included (except NodeJS, but writing a simple server in Node is also very easy).
The trick would be to set a server up that's available on your intranet, without modifying the domain.

How to get file size from clientside without using activex in javascript?

Is there any other way to get file size at client side without using ActiveX in IE?
I am getting file size from client side but, IE opens security notification popup for ActiveX controls. Is there any other way to get file size or hide ActiveX popup?
Here is code for getting file size on client side.
<html>
<body>
<form id="file">
<input type="file" id="loadfile" />
<input type="button" value="Image Size" onclick="testSize()" />
</form>
<script type="text/javascript">
function testSize(){
var browserInfo = navigator.userAgent.toLowerCase();
if(browserInfo.indexOf("msie") > -1){
/* IE */
var filepath = document.getElementById('loadfile').value;
alert(filepath + " Test ");
var myFSO = new ActiveXObject("Scripting.FileSystemObject");
var thefile = myFSO.getFile(filepath);
var imgbytes = thefile.size;
alert( "name " + thefile.name + "Size " + thefile.size );
}else{
/* Other */
var file = document.getElementById('loadfile').files[0];
alert( "name " + file.name + "Size " + file.size );
}
}
</script>
</body>
</html>
Thanks in advance.
I got solution.
There is no geniune problem with the code the problem is with internet explorer browser security settings.
Generally you face this type of error when you want to open a text file or some excel files on a remote server
go to internetoptions < security < customlevel < initialize and script active x controls not marked safe for scripting and mark them enabled and i think your problem will be removed
thanks.

Categories

Resources