Adding HTML slideshow to multiple pages (without using frames) - javascript

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

Related

How to add an HTML block to MailChimp template

I'm trying to add HTML code to my custom template on MailChimp. For each newsletter I am using a widget code from my affiliate network. I think the best way to add in the HTML code into each MailChimp newsletter is to add an HTML block to my template. However, I can't figure out how to do this. Does anyone know how I could do this, or what the best solution would be?
Here is some of the code I've tried, and it does not work to make an HTML element.
<table border="0" cellpadding="0" cellspacing="0" width="100%" class="mcnCodeBlock" style="border-collapse:collapse;mso-table-lspace:0pt;mso-table-rspace:0pt;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;" mc:repeatable mc:variant="HTML">
<tbody class="mcnTextBlockOuter">
<tr>
<td valign="top" class="mcnTextBlockInner" style="mso-line-height-rule:exactly;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;">
<div class="mcnTextContent" style="color:#656565;font-family:Helvetica;font-size:12px;line-height:150%;text-align:center;" mc:edit="html">
Use your own custom HTML
</div>
</td>
</tr>
</tbody>
</table>
This is an example of the type of code I would like to add in to each newsletter. (The code creates a product widget.)
<!-- COLLECTIVE WIDGET CODE START -->
<div class="shopsense-widget" style="text-align:center" data-options="%7B%22widgetId%22%3A%22599ae0a3dd4edb8d76b68fef%22%2C%22version%22%3A1%2C%22pid%22%3A%22uid8481-39636191-81%22%2C%22size%22%3A150%2C%22columns%22%3A3%2C%22rows%22%3A2%2C%22url%22%3A%22https%3A%2F%2Fapi.shopstyle.com%2Fapi%2Fv2%22%2C%22iframeHeight%22%3A390%2C%22iframeWidth%22%3A555%7D">
<script>
!function(doc,s,id){ var e, p, cb; if(!doc.getElementById(id)) { e = doc.createElement(s); e.id = id; cb = new Date().getTime().toString(); p = '//shopsensewidget.shopstyle.com/widget-script.js?cb=1503338936395?cb=' + cb; e.src = p; doc.body.appendChild(e); } if(typeof window.ss_shopsense === 'object'){ if(doc.readyState === 'complete'){ window.ss_shopsense.init(); } } }(document, 'script', 'shopsensewidget-script');
</script>
<iframe src="//shopsensewidget.shopstyle.com/#/?options=%7B%22widgetId%22%3A%22599ae0a3dd4edb8d76b68fef%22%2C%22version%22%3A1%2C%22pid%22%3A%22uid8481-39636191-81%22%2C%22size%22%3A150%2C%22columns%22%3A3%2C%22rows%22%3A2%2C%22url%22%3A%22https%3A%2F%2Fapi.shopstyle.com%2Fapi%2Fv2%22%2C%22iframeHeight%22%3A390%2C%22iframeWidth%22%3A555%7D"
height="390px"
width="555px"
seamless style="border: 0;">
</iframe>
</div>
<!-- COLLECTIVE WIDGET CODE END -->
Unfortunately, you are trying to add script to an HTML email, which just isn't possible nor recommended. You CAN fake a server side solution, but direct injection of a script is a no-go.
Read this article for some clarity on the subject :)

moving a function to java script

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

css on a class depending on what is contained

I have a share point calender and i want to color code difrent blocks depending on what reg number they contain (its for a school's minibuses)
How do i set the background color of .ms-cal-eworkday if a.ms-cal-tweekitem contains "EF04 WTR"
I need to do this in js/jquery as i don't have the abity to edit the aspx (council politics)
Each entry looks like this.
<td class="ms-cal-eworkday" rowspan="6">
<table cellpadding="0" cellspacing="0" border="0" class="ms-cal-tweekitem" dir="">
<tbody><tr>
<td valign="top" href="/schools/ecclesfield/newdemosite/minibus-booking/Lists/Minibus/DispForm.aspx?ID=3" onclick="GoToLink(this);return false;" target="_self">
<div>
<img src="/_layouts/images/blank.gif" width="50" height="1" alt=""><br>
<img src="/_layouts/images/recursml.gif" class="ms-cal-hidden" alt="" align="absmiddle">
<a onfocus="OnLink(this)" class="ms-cal-dayitem" href="/schools/ecclesfield/newdemosite/minibus-booking/Lists/Minibus/DispForm.aspx?ID=3" onclick="GoToLink(this);return false;" target="_self" tabindex="5">
<nobr>03:00 PM</nobr>
<br>
<b>test2</b>
<br>
EF04 WTR
</a>
</div>
</td>
</tr>
</tbody></table>
</td>
I know the code is a bit of mess that's just how sharepoint works :(
Thanks in advance.
Lewis
Well one way is too loop through the table and check each cell.
$(function(){
$('.ms-cal-dayitem').each(function(){
if( $(this).text().indexOf("EF04 WTR") != -1 ) {
$(this).closest('.ms-cal-eworkday').css("background-color","blue");
}
});
});
Obviously change the colour to suit, but this would set the background red for any td.ms-cal-eworkday that contains a.ms-cal-dayitem with the text EF04 WTR...
$("a.ms-cal-dayitem").filter(function() {
return $(this).text().indexOf("EF04 WTR") != -1;
}).closest("td.ms-cal-eworkday").css("background-color", "red");
filter() means it will only return the elements that match the criteria, which in this case is containing the relevant text.
In the same line that above answers my only change on the aproach would be to create classes in the css and then add or remove class with jQuery, but just a detail

Cannot access Preview button in Report View from button in DIV on same ASPX page

<div id='popup'>
<input id='btnConfirm'/>
</div>
$("#btnConfirm").click(function () {
var frame = $('#[id$=ReportViewer1ParameterArea]'); //get the frame
//s57 is a table element in the viewer
frame.contents().find("#Preview")
.click(
function () {
alert('hover!');
}
);
});
Below is part of the HTML rendered by Telerik Report Viewer
<iframe id="ctl00_ctl00_MainContent_MainContent_ReportViewer1ParametersArea" scrolling="auto" width="100%" height="0px" frameborder="0" align="left" src="/Telerik.ReportViewer.axd?instanceID=0001be3494c046c69b091014203c2914&culture=en-US&uiculture=en-US&optype=Parameters" style="height: 26px;">
<table id="parametersTable" cellspacing="0" cellpadding="0" border="0" style="width:100%;border-collapse:collapse;">
<tr id="parametersRow">
<td valign="middle" align="center" rowspan="2">
<input id="Preview" type="submit" onclick="return ParametersPage.Validate();" value="Preview" name="Preview">
</td>
</tr>
Question :
I need to access the Preview button ID="Preview" in the Report Viewer from a DIV that contains button with ID= btnConfirm on the ASPX page as given above in the JQuery script. The ASPX page contains the Telerik Report Viewer. I put code in the
$("#btnConfirm").click(function () event but that does not work. Can you give me ideas please?
Try using this selector:
var frame = $('[id$="ReportViewer1ParameterArea]"');
Removing the # and adding quotes " around the value.
The below code is what I developed to make my code work:
var reportFrame = document.getElementById('ctl00_ctl00_MainContent_MainContent_ReportViewer1ParametersArea');
var reportDocument = reportFrame.contentWindow.document;
var body = reportDocument.getElementsByTagName("body")[0];
$(body).contents().find("#Preview").click();

Can't make JavaScript work, is it an ID issue?

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

Categories

Resources