I've created a simple script that randomly opens sites from a list. I've recently tried to add a feature that enables users to choose the wait (in milliseconds) between the open and close of each page. Here is my code:
<!DOCTYPE html>
<html>
<head>
<title>Smokescreen</title>
</head>
<body align="center" style="font-family:monospace">
<h2 align="center" style="font-family:monospace">
SmokeScreen
</h2>
<h3 align="center" style="font-family:monospace">
SmokeScreen is a JavaScript program that opens a random site every 3 seconds,
</h3>
<h3 align="center" style="font-family:monospace">
to create a "smokescreen" over your browser history, preventing anyone from [easily] finding your information.
</h3>
<h4 align="center" style="font-family:monospace">To exit, close the original window that has the text "Smokescreen" in the title.</h4>
<p align="center" style="font-family:monospace">
Source Code / Learn More
<br />
<div style="width: 300px; border: 25px solid #800000; margin:0 auto; font-family:monospace;" align="center">
<h4 align="center" style="font-family:monospace">Milliseconds to wait before closing page:</h4>
<h4 id="one" align="center" style="font-family:monospace"></h4>
<button onclick="millisecs = prompt('New time to wait (in milliseconds)?'); if ( isNaN(milliseconds) ) {millisecs = millisecsBackup} else {millisecsBackup = millisecs} document.getElementById('one').innerHTML = millisecs;" style="font-family:monospace" align="center">Set Wait Time</button>
<br />
<br />
</div>
<br />
<div style="margin:0 auto; font-family:monospace" align="center">
<button onclick="getRandom(0, list.length, millisecs);" style="font-family:monospace" align="center">Start!</button>
</div>
</p>
<script src="script.js"></script>
<script>
var millisecs = 3000;
var millisecsBackup = 3000;
document.getElementById("one").innerHTML = millisecs;
</script>
</body>
</html>
For some reason, the text in the h4 with the id of one isn't updating when I type in different numbers. What am I doing incorrectly?
You're checking if (isNaN(milliseconds)) but you called your variable millisecs so it is throwing an error.
If you're using a modern browser, try opening the developer tools (F12 on windows / CMD+OPT+i on mac) and checking the console.
Also please look into moving your inline styles / onclicks to <style> and <script> tags :)
Related
I am new to the site (and coding) so please bear with me!
I am trying to add the following clickable slideshow to my site in a way that means I can change the images in one file (HTML or JS) and this be reflected on every page on which the slideshow is called:
<table border="0" cellpadding="0">
<td width="100%">
<img src="image1.bmp" width="200" height="200" name="photoslider"></td>
</tr>
<tr>
<td width="100%">
<form method="POST" name="rotater">
<div align="center">
<center><p>
<script language="JavaScript1.1">
var photos=new Array()
var text=new Array()
var which=0
var what=0
photos[0]="image1.bmp"
photos[1]="image2.bmp"
photos[2]="image3.bmp"
text[0]="Image One"
text[1]="Image Two"
text[2]="Image Three"
window.onload=new Function("document.rotater.description.value=text[0]")
function backward(){
if (which>0){
window.status=''
which--
document.images.photoslider.src=photos[which];
what--
document.rotater.description.value=text[what];
}
}
function forward(){
if (which<photos.length-1){
which++
document.images.photoslider.src=photos[which]
what++
document.rotater.description.value=text[what];
}
else window.status='End of gallery'
}
function type()
{
alert("This textbox will only display default comments")
}
</script>
<p><input type="text" name="description" style="width:200px" size="50">
<p><input type="button" value="<<Back" name="B2"
onClick="backward()"> <input type="button" value="Next>>" name="B1"
onClick="forward()"><br />
</p>
</center>
</div>
</form>
</td>
</tr>
Currently I have used:
<script type="text/javascript" src="images.js"></script>
in the relevant html div. to call a simple .js file which displays the images in one long list, e.g.
document.write('<p>Image One</p>')
document.write('<img src="image1small.png" alt=Image One; style=border-radius:25px>')
document.write('<p>Image Two</p>')
document.write('<img src="image2small.png" alt=Image Two; style=border-radius:25px>')
I have tried every way I can think of, and searched many posts on here to try and get the slideshow to display within the same div. I have copied the html code into the .js file and appended it with document.write on every line, I have tried / on every line, I have tried 'gettingdocument.getElementById', but nothing works!
The slideshow code itself is fine; if I put this directly onto each page then it works correctly, I just can't seem to 'link' to this code and have it run so anything appears.
Please provide the simplest possible solution for this, without any need to install jquery plugins, or use anything other than basic HTML and JS.
There were alot of small bugs, i fixed them for you. you didn't put a semicolon after your javascript statements, tey aren't neccesary but it's cleaner code, you didn't exit alot of html tags
<table border="0" cellpadding="0">
<tr>
<td width="100%">
<img src="image1.bmp" width="200" height="200" name="photoslider">
</td>
</tr>
<tr>
<td width="100%">
<form method="POST" name="rotater">
<div align="center">
<center>
<p>
<p id="description" style="width:200px" size="50"></p>
<p><a onClick="backward()"><img src="imageback.png" alt="back" />Back Image</a>
<p><a onClick="forward()"><img src="forward.png" alt="forward" />Forward Image</a>
</p>
</center>
</div>
</form>
</td>
</tr>
Javascript:
(function() {
var photos=[];
var text= [];
var which=0;
var what=0;
photos[0]="image1.bmp";
photos[1]="image2.bmp";
photos[2]="image3.bmp";
text[0]="Image One";
text[1]="Image Two";
text[2]="Image Three";
document.getElementById('description').innerHTML = text[0]
backward = function(){
if (which>0){
which--;
window.status='';
what--;
console.log(which);
document.images.photoslider.src=photos[which];
document.getElementById('description').innerHTML = text[what];
}
}
forward = function(){
if (which < (photos.length-1)){
which++;
console.log(which);
document.images.photoslider.src=photos[which];
what++;
document.getElementById('description').innerHTML = text[what];
}
else {
document.getElementById('description').innerHTML = 'End of gallery';
}
}
function type()
{
alert("This textbox will only display default comments")
}
})();
And last but not least i've created the fiddle to show you it's working:
http://jsfiddle.net/45nobcmm/24/
You can create a javascript file that search for an element and change the innerHTML of the element to the slideshow you want to show.
For example this could be the script:
var slideshow = document.getElementById('slideshow');
slideshow.innerHTML = 'Your slideshow html';
and your main html page should have a slideshow div.
but you need to know that it's not the best solution, you should learn PHP or another back-end language and than you could use include('page.html'); for example
I need to pull the function out of the following html document, create a separate js document that will contain the function and modify my existing code so that it includes my js file. Then I must create a new function in my html file called "DoTheLink." I will call that function from the function in my js file. "DoTheLink" will be passed the website variable and will set the onclick attribute for the button.
Here is what I have to work with:
<!DOCTYPE html>
<html>
<head>
<title>funky jumper </title>
</head>
<body>
<script>
var surfCaption="You\'ve selected: Bird Rock Surf Cam";
var surfButton="Bird Rock Surf Cam";
var surfWeb="http://www.surfline.com/surf-report/birdrock-7-california_4249";
var grandmaCaption="You\'ve selected: Grandma\'s Weather";
var grandmaButton="Grandma\'s Weather";
var grandmaWeb="http://www.weather.com/weather/today/Bronx+NY+10463:4:US";
var dollCaption="You\'ve selected: Noodle-head sewing";
var dollButton="Noodle-head sewing";
var dollWeb="http://www.noodle-head.com/2010/01/another-round-of-black-apple-dolls.html";
</script>
<div style="text-align: center">
<table align="center">
<td> <img src="http://nees.oregonstate.edu/killer_wave/wave.jpg" alt="Surf" border="3" height="280" width="172" onclick="uno(surfCaption, surfButton, surfWeb);">
</td>
<td> <img src="http://wirednewyork.com/images/city-guide/liberty/liberty.jpg" alt="Grandma's Weather" border="3" height=280 width=200
onclick="uno(grandmaCaption, grandmaButton, grandmaWeb);">
</td>
<td> <img src="http://4.bp.blogspot.com/__A1V8kztPXs/S1XYcpBScbI/AAAAAAAAA00/S_nd0bNtUR8/s640/helpfulhannahpresent3.jpg" alt="Noodle-head" border="3" height=280 width=180
onclick="uno(dollCaption, dollButton, dollWeb);">
</td>
</table>
<p id="captionUnderTable" >Nothing Selected</p>
<br>
<button id="NewButton" >Click on a picture, then click me to go!</button>
</div>
<script>
function uno(Caption, Button, Web)
{
document.getElementById("captionUnderTable").innerHTML=Caption;
document.getElementById("NewButton").innerHTML=Button;
document.getElementById("NewButton").setAttribute('onclick','window.location.href="'+Web+'";')
<!--When the picture is clicked, go get the variable associated with that picture-->
}
</script>
</body>
</html>
If you're trying to put what is between the < script > tags in another file, this link might help: http://www.htmlgoodies.com/beyond/javascript/article.php/3470901/So-You-Want-An-External-JavaScript-Huh.htm
I'm trying to get a message to appear when a user clicks the image that's in a the "lifeCalculatorButton" ID, but I can't figure out how to make it work. I know that the html doc is referencing the js doc fine, so that's not the issue. Any ideas?
<html>
<head>
<link rel="Stylesheet" type="text/css" href="apps.css" />
<script type="text/javascript" src="apps.js"></script>
<title>my apps</title>
</head>
<body>
<div id="breaks">
<a href="http://info" > <img src="homeicon.png" /> </a>
<br>
<br>
<br>
<br>
<br>
<div id="appTable" style="float: left">
<table border="0" id="appTable">
<tr>
<td>life calculator</td>
</tr>
<tr>
<td>punny!</td>
</tr>
<tr>
<td>drink roulette (on its way!)</td>
</tr>
</table>
</div>
<div id="arrowTable" style="float: left">
<table border="0">
<tr>
<td id="lifeCalculatorButton"><img src="arrow1.png" width="45"</td>
</tr>
<tr>
<td id="punnyButton"><img src="arrow1.png" width="45"/></td>
</tr>
<tr>
<td id="drinkRouletteButton"><img src="arrow1.png" width="45"/></td>
</tr>
</table>
</div style="clear: both">
<div id="content">
my apps :)
</div>
And here's the JavaScript:
var foo = document.getElementById('lifeCalculatorButton');
foo.onClick = function (){
document.getElementById('content').innerHTML = 'foo';
};
Try changing the onclick event to all lowercase.
var foo = document.getElementById('lifeCalculatorButton');
foo.onclick = function (){
document.getElementById('content').innerHTML = 'foo';
};
EDIT
The below code works in both Firefox and IE. I've changed the event from foo.onClick to foo.onclick. Make sure your javascript block is at the end of the page or the call to getElementById will return null. Also, you should close the unclosed <img> tag and remove the style="clear: both" from the second to last closing </div> near the bottom of your page.
<html>
<head>
<link rel="Stylesheet" type="text/css" href="apps.css" />
<title>my apps</title>
</head>
<body>
<div id="breaks">
<img src="homeicon.png" />
<br /><br /><br /><br /><br />
<div id="appTable" style="float: left">
<table border="1" id="appTable">
<tr><td>life calculator</td></tr>
<tr><td>punny!</td></tr>
<tr><td>drink roulette (on its way!)</td></tr>
</table>
</div>
<div id="arrowTable" style="float: left">
<table border="1">
<tr><td id="lifeCalculatorButton"><img src="arrow1.png" width="45"/></td></tr>
<tr><td id="punnyButton"><img src="arrow1.png" width="45"/></td></tr>
<tr><td id="drinkRouletteButton"><img src="arrow1.png" width="45"/></td></tr>
</table>
</div>
<div id="content">
my apps :)
</div>
</body>
</html>
<script type="text/javascript">
var foo = document.getElementById('lifeCalculatorButton')
foo.onclick = function (){
document.getElementById('content').innerHTML = 'foo';
};
</script>
EDIT
If you are using an external javascript file you must use the window.onload event handler to register your handler to ensure the page has completely loaded.
window.onload = function () {
var foo = document.getElementById('lifeCalculatorButton')
foo.onclick = function (){
document.getElementById('content').innerHTML = 'foo';
};
};
First, you seem to have a typo here:
<td id="lifeCalculatorButton"><img src="arrow1.png" width="45"</td>
The <img> tag is not closed properly.
You also have to either move the <script> include at the bottom of your document or attach to the window load event to make sure that your script is executed after the elements in question appear in the DOM:
window.onload = function () {
var foo = document.getElementById("lifeCalculatorButton");
// ...
};
It may be overkill but this could be a good excuse to introduce yourself to jQuery or similar framework. It makes this kind of work trivial to implement. See this fiddle for a working examlpe using jQuery.
If you don't want to use jQuery your javascript looks ok as this fiddle works.
As others have said make sure you are not assigning the event handler until after the DOM is loaded. This is done in the pure javascript fiddle above using the following code
<script type='text/javascript'>//<![CDATA[
window.onload=function(){
var foo = document.getElementById('Clickable');
foo.onclick = function (){
alert("See It Works");
};
}//]]>
On a side note following a comment above, the cursor will not change on hover as the browser is still interpreting the element as what ever it is, in this case, a table cell. The only difference is that it now has an event assigned to it. To have the cursor change you will need to do this using CSS.
Does it need to be the td that holds the id? Why not use an a tag to wrap around the image (and as suggested close the img tag correctly with />). Apply the onclick to the a tag and call a function with a return false afterwords to bypass normal behavior... and obviously, in your onclick you can call whatever function u want
I have a page and when I mouse over the links it changes an image and some html on another portion of the page. However Im wondering how this script works and when I look at the script at the top of the page:
<script type="text/javascript">
var CONTENT_CURRENT = 0;
showContent = function() {
if (CONTENT_CURRENT > 0) {
var o = YAHOO.util.Dom.get('content' + CONTENT_CURRENT);
o.style.display = 'none';
var a = YAHOO.util.Dom.get('link' + CONTENT_CURRENT);
a.style.color = '#46689e';
}
var c = YAHOO.util.Dom.get('content' + arguments[0]);
c.style.display = 'block';
var l = YAHOO.util.Dom.get('link' + arguments[0]);
l.style.color = '#000000';
CONTENT_CURRENT = arguments[0];
};
YAHOO.util.Event.onDOMReady(function() { showContent('1'); });
</script>
How is this script setting the an element on the page? The actual page is at:
Link to site
Under the title 'Streaming Software Products'...
There is another code block you need to look at to understand this code
<div class="real-products-mid-lh">
<a id="link5" href="/products/helix_server.aspx" onmouseover="showContent('5')">Helix Server</a><br />
<a id="link1" href="/products/rlp.aspx" onmouseover="showContent('1')">Real License Program</a><br />
<a id="link2" href="/products/helix_security_manager.aspx" onmouseover="showContent('2')">Helix Security Manager</a><br />
<a id="link3" href="/products/real_player_enterprise_manager.aspx" onmouseover="showContent('3')">RealPlayer Enterprise</a><br />
<a id="link4" href="/products/helix_mobile_server.aspx" onmouseover="showContent('4')">Helix Mobile Server</a><br />
<a id="link6" href="/products/helix_proxy.aspx" onmouseover="showContent('6')">Helix Proxy</a><br />
<a id="link7" href="/products/real_producer.aspx" onmouseover="showContent('7')">RealProducer</a><br />
<a id="link8" href="/products/capture_station.aspx" onmouseover="showContent('8')">Accordent Capture Station</a><br />
<a id="link9" href="/products/elp.aspx" onmouseover="showContent('9')">Real Education Licensing</a><br />
<a id="link10" href="/products/helix_mobile_producer.aspx" onmouseover="showContent('10')">Helix Mobile Producer</a>
</div>
Here each link in the list calls showContent with an index as the argument. There are a bunch of divs below like this one:
<div id="content1" style="display:none;">
<div class="real-products-mid-rh">
<div class="real-products-logos">
<table width="100%" cellpadding="0" cellspacing="0" style="border:1px solid #d6d6d6; height:107px;">
<tr>
<td align="center"><img src="/_common/images/logo_real_sm.gif" alt="Real License Program" style="vertical-align:middle" /></td>
</tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0" style="border-left:1px solid #d6d6d6; border-right:1px solid #d6d6d6; border-bottom:1px solid #d6d6d6; padding-top:5px; padding-bottom:5px;">
<tr align="center">
<td><strong>LICENSE PROGRAM</strong></td>
<td><img src="/_common/images/px_more.gif" alt="Find out more" /></td>
<td> </td>
</tr>
</table>
</div>
<p><strong>Cost effective and all encompassing RealNetworks License Programme available exclusively to UK enterprise customers<br />
Real License Program <img src="/_common/images/px_more.gif" alt="Find out more" /></strong></p>
</div>
</div>
That div's ID is "content1". So the showContent function does three things:
If there is a content div that is
visible, make it hidden
(display=none)
Make the desired content div
visible.
Set the current visble content
index.
This cause the content to the right of the links to change on mouse over.
YAHOO.util.Dom.get() works like document.getElementById()
o.style.display = 'none'; // hides current content
a.style.color = '#46689e'; // paints current link blue
c.style.display = 'block'; // displays new content
l.style.color = '#000000'; // paints new link black
<style>
.address_bar
{
width:1100px;
color:#333333;
font-family:Verdana, Geneva, sans-serif;
}
\#browser
{
width:90%;
}
</style>
<script language="javascript" type="text/javascript">
function go_to_page()
{
var url = document.getElementById("address").value;
//window.open(url,"browser");
document.getElementById("browser").src = url;
}
</script>
<body>
<div>
<div style="float:left;">
<input type="text" name="address" id="address" class="address_bar" value="http://"/>
</div>
<div style="float:left;">
<input type="button" name="go" id="go" value="Go >> " onclick="go_to_page()"/>
</div>
<div>
<iframe name="browser" id="browser" style="height:750px;">
</iframe>
</div>
</div>
</body>
In above example if I want to open
1. http://mail.yahoo.com
2. http://www.gmail.com
then It automatically removes the iframe. what I do? I want every site is open in same iframe.
These sites have what is called a frame breakout, to prevent them being loaded in a frame. There are some scripts to disable frame breakout, with varying results.
Of course, loading 3rd party sites in an frame within your own website is kind of stealing, and profiting of their success, but I trust that you just want a way to check both of your e-mail accounts.
You can't. For security reasons, these websites won't load if they "know" they are in an iframe.