Javascript Port Watching
Nov 7, 2005Basically, I want to have a javascript that will watch for data coming
in on a specific port - like HTTP on port 80, etc. Is this at all
possible with pure javascript?
Basically, I want to have a javascript that will watch for data coming
in on a specific port - like HTTP on port 80, etc. Is this at all
possible with pure javascript?
Okay, this an attempt to port PHP's date() function as much as possible to JavaScript. Could use some refactoring though. Any critique, comments, appraisal and any other opinion is very welcome. Feel free to discuss and also take a look at beetles code here: http://www.codingforums.com/showthread.php?s=&threadid=11069
Oh, and the date() function is described here: http://www.php.net/manual/en/function.date.php
Date.prototype.monthNames = new Array(
"January", "February", "March", "April",
"May", "June", "July", "August",
"September", "October", "November", "December"
);
Date.prototype.dayNames = new Array(
"Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"
);
Date.prototype.format = function (formatStr) {
var heap = formatStr.split("");
var resHeap = new Array(heap.length);
var escapeChar = ""; // you can change this to something different, but
// don't use a character that has a formatting meaning,
// unless you want to disable it's functionality
// go through array and extract identifiers from its fields
for (var i = 0; i < heap.length; i++) {
switch(heap[i]) {
case escapeChar:
resHeap[i] = heap[i+1];
i++;
break;
case "a": // "am" or "pm"
var temp = this.getHours();
resHeap[i] = (temp < 12) ? "am" : "pm";
break;
case "A": // "AM" or "PM"
var temp = this.getHours();
resHeap[i] = (temp < 12) ? "AM" : "PM";
break;
case "d": // day of the month, 2 digits with leading zeros; i.e. "01" to "31"
var temp = String(this.getDate());
resHeap[i] = (temp.length > 1) ? temp : "0" + temp;
break;
case "D": // day of the week, textual, 3 letters; i.e. "Fri"
var temp = this.dayNames[this.getDay()];
resHeap[i] = temp.substring(0, 3);
break;
case "F": // month, textual, long; i.e. "January"
resHeap[i] = this.monthNames[this.getMonth()];
break;
case "g": // hour, 12-hour format without leading zeros; i.e. "1" to "12"
var temp = this.getHours();
resHeap[i] = (temp <= 12) ? temp : (temp - 12);
break;
case "G": // hour, 24-hour format without leading zeros; i.e. "0" to "23"
resHeap[i] = String(this.getHours());
break;
case "h": // hour, 12-hour format; i.e. "01" to "12"
var temp = String(this.getHours());
temp = (temp <= 12) ? temp : (temp - 12);
resHeap[i] = (temp.length > 1) ? temp : "0" + temp;
break;
case "H": // hour, 24-hour format; i.e. "00" to "23"
var temp = String(this.getHours());
resHeap[i] = (temp.length > 1) ? temp : "0" + temp;
break;
case "i": // minutes; i.e. "00" to "59"
var temp = String(this.getMinutes());
resHeap[i] = (temp.length > 1) ? temp : "0" + temp;
break;
case "I": // "1" if Daylight Savings Time, "0" otherwise. Works only on the northern hemisphere
var firstDay = new Date(this.getFullYear(), 0, 1);
resHeap[i] = (this.getTimezoneOffset() != firstDay.getTimezoneOffset()) ? (1) : (0);
break;
case "J": // day of the month without leading zeros; i.e. "1" to "31"
resHeap[i] = this.getDate();
break;
case "l": // day of the week, textual, long; i.e. "Friday"
resHeap[i] = this.dayNames[this.getDay()];
break;
case "L": // boolean for whether it is a leap year; i.e. "0" or "1"
resHeap[i] = (this.getFullYear() % 4) ? false : true;
break;
case "m": // month; i.e. "01" to "12"
var temp = String(this.getMonth() + 1);
resHeap[i] = (temp.length > 1) ? temp : "0" + temp;
break;
case "M": // month, textual, 3 letters; i.e. "Jan"
resHeap[i] = this.monthNames[this.getMonth()];
break;
case "n": // month without leading zeros; i.e. "1" to "12"
resHeap[i] = this.getMonth() + 1;
break;
case "O": // Difference to Greenwich time in hours; i.e. "+0200"
var minZone = this.getTimezoneOffset();
var mins = minZone % 60;
var hour = String(((minZone - mins) / 60) * -1);
if (hour.charAt(0) != "-") {
hour = "+" + hour;
}
hour = (hour.length == 3) ? (hour) : (hour.replace(/([+-])(d)/, "$1" + 0 + "$2"));
resHeap[i] = hour + mins + "0";
break;
case "r": // RFC 822 formatted date; e.g. "Thu, 21 Dec 2000 16:01:07 +0200"
var dayName = this.dayNames[this.getDay()].substr(0, 3);
var monthName = this.monthNames[this.getMonth()].substr(0, 3);
resHeap[i] = dayName + ", " + this.getDate() + " " + monthName + this.format(" Y H:i:s O");
break;
case "s": // seconds; i.e. "00" to "59"
var temp = String(this.getSeconds());
resHeap[i] = (temp.length > 1) ? temp : "0" + temp;
break;
case "S": // English ordinal suffix for the day of the month, 2 characters; i.e. "st", "nd", "rd" or "th"
var temp = this.getDate();
var suffixes = ["st", "nd", "rd"];
var suffix = "";
if (temp >= 11 && temp <= 13) {
resHeap[i] = "th";
} else {
resHeap[i] = (suffix = suffixes[String(temp).substr(-1) - 1]) ? (suffix) : ("th");
}
break;
case "t": // number of days in the given month; i.e. "28" to "31"
resHeap[i] = this.getDay();
break;
/*
* T: Not implemented
*/
case "U": // seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
// remember that this does not return milisecs!
resHeap[i] = Math.floor(this.getTime() / 1000);
break;
case "w": // day of the week, numeric, i.e. "0" (Sunday) to "6" (Saturday)
resHeap[i] = this.getDay();
break;
case "W": // ISO-8601 week number of year, weeks starting on Monday
var startOfYear = new Date(this.getFullYear(), 0, 1, 0, 0, 0, 0);
var firstDay = startOfYear.getDay() - 1;
if (firstDay < 0) {
firstDay = 6;
}
var firstMonday = Date.UTC(this.getFullYear(), 0, 8 - firstDay);
var thisDay = Date.UTC(this.getFullYear(), this.getMonth(), this.getDate());
resHeap[i] = Math.floor((thisDay - firstMonday) / (1000 * 60 * 60 * 24 * 7)) + 2;
break;
case "y": // year, 2 digits; i.e. "99"
resHeap[i] = String(this.getFullYear()).substring(2);
break;
case "Y": // year, 4 digits; i.e. "1999"
resHeap[i] = this.getFullYear();
break;
case "z": // day of the year; i.e. "0" to "365"
var firstDay = Date.UTC(this.getFullYear(), 0, 0);
var thisDay = Date.UTC(this.getFullYear(), this.getMonth(), this.getDate());
resHeap[i] = Math.floor((thisDay - firstDay) / (1000 * 60 * 60 * 24));
break;
case "Z": // timezone offset in seconds (i.e. "-43200" to "43200").
resHeap[i] = this.getTimezoneOffset() * 60;
break;
default:
resHeap[i] = heap[i];
}
}
// return joined array
return resHeap.join("");
}
What I would like to do is watch a countdown timer on a page, like the ones on swoopo.co.uk and then perfom an action depending on what time is left on the timer.
I've installed DOM inspector on Firefox and poked around with javascript shell and I think I've figured out how to read the timer and assign that to a variable, something like this -
var timer=document.getElementById('counter_index_page_162980').innerHTML;
Now I need to watch that so I guessed this would do -
while (timer!=="00:00:01")
{
var timer=document.getElementById('counter_index_page_162980').innerHTML;
}
alert('timer at 1 sec!');
But that just brings up an "unresponsive script" error in my browser.
Am I even close to the mark? I know I'm not going to win any auctions with this but I've already paid for the bids so I may as well use them now.
Is JavaScript able to send/listen for data on a specific port? I'm seeking
a solution to real time data interaction with my web server that doesn't
require refreshing the page. I.e., a chat room, where the data can be
broadcast from the server arbitrarily and displayed by the client
browser(s). To accomplish the data transmission can I use JS, or do I need
to augment my client-side platform to something like Java, et al?
I'm a newbie to javascript programming and I'm seeking on a solution on how to connect to a tcp port using javascript. Basically, we have phone server that is constantly streaming XML data on port 1024 (serverIP:1024). I've ran a packet sniffer and was able to gather the elements and attributes for the XML data that the server is streaming. Now, I have a test XML parser which works with the XML document using the elements and attributes i've gathered from the packet sniffer. Is there a way for me to connect to the TCP port i've mentioned using javascript and incorporate it with the XML parser that I have. code...
View 3 Replies View RelatedI am planning to use a USB barcode scanner and use web browsers as my interface.
Is it possible to parse the USB port via javascript? (or any client-side languages)
How to do serial port communication using Javascript?
View 2 Replies View RelatedI have been directed from .NET section to this section. My original post and question are here. forums.devshed.com/net-development-87/asp-net-how-to-send-data-to-parallel-port-600691.html
Is it possible to send data to parallel port using javascript?
I know about the same-origin policy and that one of the only ways to load data from a cross-domain is to load it as JSON. However, all I am trying to do is access data from a server on another port (which I believe the browser still treats as cross-domain). I need to do this because the server my application is on is a map server and the other server (Apache) is the only one that can handle php scripts. I have also tried out the plug-in from [URL] and while it works when I do $('#phpContent').load('http://www.google.com'); it doesn't work when I try $('#phpContent').load('http://localhost:80/mapScripts/getFiles.php'); I have also tried$.get('http://localhost:80/mapScripts/getFiles.php', function(data) { $('#phpContent').html(data); });
So here I am breaking my brain and do not know what else to attempt.
I have created a payment system using Jquery. The problem I run into is when I move from http to https. I get the following error: Error: [Exception... "Access to restricted URI denied" code: "1012"
[Code]...
Hides the element by sliding it down.
$("div").click(function () { $(this).hide("slide", { direction: "down" }, 1000); });
I am new to Jquery. How do I reverse this code to slide element into viewport as opposed to slide out of view port. This is the link to the effect [URL]. What I want to do is the element will be hidden originally on loading the page and then slides into view with a click anywhere on the page, an anchor or after a few seconds.
I am working on a robot project, that is required to create a website to control the robot via serial port.. The website is plainly html, no linking to database is needed...
I have no idea how and what language to use and can JavaScript communicate with serial port? and how?
I have got this xml file which has a background params which is <background>igmp:
{theme.background_video_ip}:1234</background>.
I have done the validation to check if the igmp protocol is used like this
if (clientSpecificData.background.substr(0, 7) == "igmp:") {
Right now I am trying to find out how I can use regular expressions to check whether a port number is used at the end.
I'm trying to find the position of an element with respect to the view port area. So, when the user scrolls the page down, I want to know the x and y positions of the element with respect to the viewing (view port) area.
The overall goal is to know exactly where on the element this user clicked.
I'm working on some code and am running into brick walls. I'm trying
to write out Javascript with Javascript and I've read the clj Meta FAQ
and didn't see the answer, read many similar posts (with no luck
though), and searched through the IRT.ORG Faqs
(www.irt.org/script/script.htm).
The Javascript is designed to open an popup window and then inside that
window call another script which will resize that window. There may be
another way around this but the reason I tried this approach initially
was that I wanted to call the onload handler in the popup window to
resize the image only after the image had completely loaded. I've had
some code in the primary Javascript file (showimage.js) before that
works if the image has been cached but on the first load, it doesn't
resize properly which tells me it is probably because it is trying to
resize the window based on the image size but it isn't completely known
at that point. So I removed that code and tried placing the resizing
code in the second Javascript file (resizewindow.js). BTW I've tried
other code to open a popup image and automatically size it ie Q1443 at
irt.org but that doesn't do exactly what we need.
Even if there is another way to do this with one file, I still want to
figure out why this isn't working in case I run into it in the future.
I thought what I would need to do to use document.writeln to write
Javascript would be to escape any special characters and to break
apart the script tag ie
document.writeln('</SCRIPT>');
would become
document.writeln('</SCR' + 'IPT>');
I have a HTML page and 2 Javascript files. All files are in the same
directory and have permissions set correctly.
Here are the 3 files (keep in mind wordwrap has jacked up the
formatting):
index.html
----------
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test</title>
<SCRIPT type="text/javascript" LANGUAGE="JavaScript1.1"
SRC="showimage.js">
</SCRIPT>
</head>
<body>
Click the house<BR>
<A ONCLICK="newWindow1('house1.jpg','Nice House')"><IMG
SRC="house1thumb.jpg"></A>
</body>
</html>
showimage.js
------------
function newWindow1(pic,sitename)
{
picWindow=window.open('','','width=25,height=25,sc rollbars=1,resizable=1');
picWindow.document.writeln('<html> <head>');
picWindow.document.writeln('<SCR' + 'IPT type="text/javascript"
LANGUAGE="JavaScript1.1" SRC="resizewindow.js"></SCR' + 'IPT>');
picWindow.document.writeln('</head>');
picWindow.document.writeln('<body onload="resizewindow();">');
picWindow.document.writeln('<img src=' + pic + '>');
picWindow.document.writeln('</body> </html>');
picWindow.document.close();
}
resizewindow.js
---------------
function resizewindow()
{
// Do resizing here.
// Right now this isn't being executed
alert("resizing window");
}
Can anyone provide some pointers as to why this javascript is failing?
I'm using IE6 on Win2k and when I click on the image to open the popup
window, it does open the window but it is white with no content and the
system immediately goes from about 4% CPU usage to 100% and
consistently stays there until I kill that window with the task
manager.
Attached is a simple HTML file that adds and delete rows. In the add
row function I set an attribute "onClick" this triggers the
testMessage() function. When I try this in Firefox it works just fine
however on IE it just refuses to work.
What is interseting is the ROW that already exists has a similar
'onClick' event which works when the page is loaded, but subsequent
"row" additions to the table to not work in IE. Code:
two possibilities or the attribute type of script:
text/javascript (the one i usually use) application/x-javascript
what are the differencies between both?
depends on the html content?
for example html 4.0.1 versus xhtml 1.1?
I'm getting errors in Firefox everytime I try to run this frame resize code, but it works fine in IE. I can't seem to figure out what the problem is with it.
The error is: Error: theFrame has no properties
Line: 8
The line that the javascript console is showing an error for is in italics.
code from page:
<html>
<head>
<script type="text/javascript">
var defaultCols="100px,*";
var hiddenCols="0px,*";
function ShowHideMenu(){
theFrame = document.getElementById("framed");
if(theFrame.cols == defaultCols) theFrame.cols=hiddenCols;
else theFrame.cols=defaultCols;
}
</script>
<frameset cols="100px,*" name="framed">
<frame src="lframe.htm" name="frameMenu">
<frame src="mframe.htm" name="content">
</frameset>
</head>
<body>
</body></html>
Come someone let me know what I'm doing wrong here?
I'm already past the basics of Javascript, and i need something that takes me to the other level and teaches me the new technologies and cool stuff (drag&drop, AJAX, OOP in javascript, maybe XUL...etc). So far i found these two books:
1. Sitepoint's "The JavaScript Anthology: 101 Essential Tips, Tricks & Hacks".
2. Worx's "Professional JavaScript for Web Developers (Wrox Professional Guides)"
Both seems to cover very insteresting topics, but i can only buy one of them. So which one do you suggest?
and by the way, i've read the sample chapter 5 of Sitepoint's book, and it seems like the author(s) just put the solutions/codes there and let you figure them out on your own. Is this how the rest of the chapters are?
This is a question about defensive web browsing. Ocassionally I run into a page whose JavaScript does something that I find obnoxious. I would like to turn off JavaScript only for that page (instead of disabling it globally). It would be cool if there were some way to do this through a "bookmarkable" JavaScript snippet using the javascript: pseudoprotocol. Does anyone know any trick to do any of this?
View 2 Replies View RelatedI am looking for a method to extract the links embedded within the
Javascript in a web page: an ActiveX component, or example code in
C++/Pascal/etc. I am looking for a general solution, not one tailored
to a particular page/script.
Hopefully, the problem can be solved without recreating a complete
Javascript interpreter. Any ideas?
I have some javascript that I have written into the <body> section and it works great. But I would like to make it into a javascript function and define the function in the <head> section. Then in the <body> section write a small bit of javascript that would call the function() object. Code:
View 2 Replies View RelatedI would like to know how to write javascript such that, a part of it isnt considered as script, & rather as HTML. Code:
Ok, the layer div can be written using document.write. But, Google ad itself is a javascript isnt it. How can it be written into this? How does this work?
Ok so, this is my purpose:
- to be able to load asynchronously (via AJAX) some javascript ads (like google's or adbrite) so as to make them be loaded in the background, then update the page after the ads have loaded via innerHTML
Why?
-Because 90% of the time in my newer sites, javascript ads are the major offender in terms of speed of page rendering
My problem:
Via ajax, I can call a php file that retrieves some javascript and outputs it, XMLhttprequest returns those javascript lines, but they don't render in the page, since they miss the whole page loading, and are apparently not parsed
For example, let's say I call a php file via ajax, and it returns the output into a variable named "text" containing "document.write('hello')"
if I use xxx.innerHTML=text, nothing happens
My 1st solution:
Passing those javascript lines to eval() [like eval(text) ], but this produces a second problem, that I couldn't solve (probably because of my lack of knowledge in javascipt):
if I eval the code, it deletes my current page and renders a new one
for example, if I parse a document.write, my page disappears, and a new one is rendered with the document.write text
What I want is basically to make that "document.write" appear inside a div in my page, adding to the content (and not overwriting the whole page), much like what happens when using innerHTML
Is this even possible? How would you go about it?
I tried xxx.innerHTML=eval(outputfromphpfile) but it overwrites my whole page...
Just a quickie: is it possible to place javascript within javascript? The following is the code I am using to create a pop-up for a picture gallery. I would like to place a banner from a banner exchange in bold under each photo. When I use the code below I get an error message:
<SCRIPT language=JavaScript>
<!--
function openpic(pic_name) {
myWin= open("", "displayWindow", "width=640,height=510,status=no,toolbar=no,
menubar=no,scrollbars=yes,resizable=yes,alwaysraised=yes");
myWin.document.open();
myWin.document.write("<html><head><title>" + pic_name + "</title>");
myWin.document.write("</head><BODY><center><TABLE CELLPADDING=Ɔ' CELLSPACING=Ɔ' WIDTH=òr'>");
myWin.document.write("<br><img src=kate/image"+ pic_name + ".jpg><br>");
myWin.document.write("<br><br><BR><br><BR><br><BR>");
myWin.document.write("<script language='javascript' type='text/javascript' src='http://www.linkbuddies.com/ad.go?id=134039+2&n=3'></script>");
myWin.document.write("</center></body></html>");
myWin.document.close();
}
//-->
</SCRIPT>
Basically, on one of my sites I'm running adsense and today I added Chitika. The problem is, I can't run those type of ads through my banner advertising program.
The banner advertising program calls the banners/HTML from code like this:
<script language=JavaScript src=http://www.mysite.com/advertise/abm.asp?z=1></script>
And using that program I'm able to either choose a banner or HTML I want to display when that code above is used. It displays HTML ok... but when I try to run an ad of either adsense or chitika nothing displays on the page. The code that would be called is:
<script type="text/javascript"><!--
*Chicika code in here*
//--></script>
<script src="http://xxx/xxx/mm.js" type="text/javascript">
</script>
So... it looks like I can't have javascript call another javascript to display on a page. My question is then... how can I edit the above to make it work or how can I work around this problem? I'd really want this to work with Chitika and not so much with adsense... but it appears both Chitika and Adsense use similar javascript code.