JavaScript - How To Create A Link To Another Page, But With A Slight Catch
I would like to create a link from one page to another.
Easy - I know. But I would like that link to to take me to a certain part of the other page, specifically towards the bottom of the page. Is that possible to do? And if so, what are the different ways I can specify where in the page to go? (i.e. what are the parameters that I can play with) Thanks! Similar TutorialsFirst, I did this for testing Code: <script type="text/javascript"> <!-- var cururl = window.location.href + "?style=1" document.write(cururl); //--> </script> and it works. It gets the current url of the page and appends ?style=1 then writes out the URL. However getting it as a clickable link is what's stumping me. Code: <script type="text/javascript"> <!-- function goURL() { window.location.href + "?style=1" } //--> </script> <a href="javascript:goURL()">Go There</a> Doesn't work in my test. As you can probably see, I'm not very well versed in javascript. I have called a table through XML with four fields. One of them is Excel file name. I like to make a clickable link with Excel file name to open it. XML code: Code: <?xml version="1.0" encoding="ISO-8859-1" ?> <searchable_index> <item name="Ana" title="Data" link="doc\ana.xls">Member</item> <item name="Ana" title="Data" link="doc\ana.xls">Member</item> <item name="Ana" title="Data" link="doc\ana.xls">Member</item> <item name="Ana" title="Data" link="doc\ana.xls">Member</item> </searchable_index> Javascript code document.write('<table border="1" style="width: 100%;">'); document.write('<tr><th>name</th><th>title</th><th>link</th></tr>'); for(var i=0; i<results.length; i++) { document.write('<tr>'); document.write('<td>' + results[i].getAttribute("name") + '</td>'); document.write('<td>' + results[i].getAttribute("title") + '</td>'); document.write('<td>' + results[i].getAttribute("link")" > + '</td>'); //<a href="url">Link text</a> document.write('</tr>'); } document.write('<table>'); document.close(); Ok I have a script that uses some global arrays and a function that looks like this: function functName(p) The other params are optional so they are accessed using: functName.arguments[1] etc. My problem is an error that I can't seem to catch even though it's an easy one. array = (functName.arguments[1] != undefined && evel('window.' +functName.arguments[1]) != undefined) ? do this: or this; The second param is an arrayName. It can be sent to the function as a string or a reference ( string: 'arrayName' , ref: arrayName) both operate correctly unless the array doesn't exist. Entered as a string, if the array doesn't exist it defaults to another array as required. However, if posted as a reference and it doesn't exist it throws an error: 'arrayName' is undefined Should I just use a 'try catch' method or it just something simple I missed? Hi peeps, I thought I'd post this here as I haven't had any luck finding what I'm after but wondered it someone else had seen a slideshow that worked this way. In theory it seems simple enough to do. Description: Bascially I'd have a slideshow with several list items (or divs) within it. Now the main think with this slidshow is the list items or divs would have differing widths. The pagination would be 'Previous' and 'next' arrows. When you clicked next, it would slide along and line up the left edge of the next item/div with the left item of the slideshow. An likewise for every click. Esentially I guess you'd be sliding along the width of the 'active slide'. 2 items/divs being visible in the window is not a problem, neither is one being cropped off at the end. As the 'active' slide would always be the left most slide. Does this seem Ok, am I making any sense at all? I hope so! If anyone has seen something like this it would be great or maybe point me in the right direction. Cheers & thanks for reading, Ste Hi I'm an AS3 dev learning Javascript. I'm currently writing a simple script that loads an image as seen below. I deliberately misspell the file name to test the fail. Code: var fileName = "anImageThatDoesntExist.jpg"; var image = new Image(); image.onload = imageLoaded; try { image.src = "images/" + fileName; } catch( error ) { console.log('load error', error.message ); } finally { console.log('unable to catch error!') } function imageLoaded( event ) { console.log('image loaded'); } When I run this script I was expecting the 'catch' to pick up the error and tell me that the file doesn't exist. The 'catch' statement is ignored and 'finally' is executed. I would be very grateful if someone could let me know if I'm writing the try/catch incorrectly or whether it doesn't work in this way when loading an image. Many thanks in advance.... Hello, I am using the following javascript breadcumb script (found here http://www.javascriptsource.com/navi...eadcrumbs.html ) It works perfectly, except I'm trying to figure out how to remove and replace the "dash" ( - ) character with a space? Code: function breadcrumbs() { sURL = new String; bits = new Object; var x = 0; var stop = 0; var output = "<div class=topnav><a href=/>Home</a> > "; sURL = location.href; sURL = sURL.slice(8,sURL.length); chunkStart = sURL.indexOf("/"); sURL = sURL.slice(chunkStart+1,sURL.length) while(!stop){ chunkStart = sURL.indexOf("/"); if (chunkStart != -1){ bits[x] = sURL.slice(0,chunkStart) sURL = sURL.slice(chunkStart+1,sURL.length); } else { stop = 1; } x++; } for(var i in bits){ output += "<a href=\""; for(y=1;y<x-i;y++){ output += "../"; } output += bits[i] + "/\">" + bits[i] + "</a> > "; } document.write(output + document.title); document.write("</div>"); } Any help would be greatly appreciated. Thank you! Hi all, I have a question about following code. It is tested as working well but the problem is that I need to catch values of array registos from javascript function getData(dataSource, sql_str) in PHP and not only update values of each form element. Can you help me, plz? Code: <script language = "javascript"> function getData(dataSource, sql_str){ if (window.XMLHttpRequest){ xmlhttp=new XMLHttpRequest(); } else{ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ var registos = eval('('+xmlhttp.responseText+')'); document.getElementById("id_1").value=registos["cliente"]; document.getElementById("id_2").value=registos["designacao"]; } } xmlhttp.open("GET", dataSource+"&sql_str="+sql_str,true); xmlhttp.send(); } </script> <?php $sql_str="SELECT cliente, designacao WHERE cliente = '$cliente'"; $record=$db->sql_query($sql_str); list($registos[cliente], $registos[designacao]) = $db->sql_fetchrow($record); echo "<form id=\"form\">"; echo "<input type=\"text\" id=\"id_1\" name=\"registos[cliente]\" value=\"".$registos[cliente])."\">"; echo "<br>"; echo "<input type=\"text\" id=\"id_2\" name=\"registos[designacao]\" value=\"".$registos[designacao]."\">"; echo "<br>"; echo "<input type=\"button\" value=\"CONFIRMAR\" onclick=\"getData('mysql_query.php', '".base64_encode(serialize($sql_str))."')\">"; echo "</form>"; I've got a function that returns the value of a radio button group. However the application allows to "hide" some groups on others responses and that effectively make the radio groups not exist. This causes issues with calculations using the total value of the groups combined. I need a way to return a value of '0.00' IF the function does not find the group/returns an error.This is what I currently got to but doesnt work. The function does not work at all. Code: function funcRadioCalc(RadioName) { var chkList1= document.getElementById (RadioName); var arrayOfCheckBoxes= chkList1.getElementsByTagName("input"); var bob; try { for( var i=0;i<arrayOfCheckBoxes.length;i++){ if (arrayOfCheckBoxes[i].checked) { bob= arrayOfCheckBoxes[i].value; if (bob!=undefined||bob!=""){ throw "yep"; }else{ throw "nope"; } } } catch (er){ if(er=="nope") { return "0.00"; } if(er=="yep") { return bob; } } } If you try some codes and then catch exception, it should catch the exception when there is. However, if there is a setInterval method in the try clause, then the exception cannot be caught... why??? the following works ( a usual method is invoked in the try clause): Code: <script language="javascript" type="text/javascript"> function invoke() { var i=0; return i.x.y; } try { alert(invoke()); } catch(ex){ alert(ex); } //Any Exception will be caught. </script> if the highlighted line is changed as below (using setInterval method), then it fails... Code: <script language="javascript" type="text/javascript"> function invoke() { var i=0; return i.x.y; } try { setInterval(alert('invoke())',1000); } catch(ex){ alert(ex); } //The Exception will NOT be caught. </script> any idea? thx in advance What happens in Javascript when you do not catch a thrown exception? Does the script get terminated prematurely? Hello, I want to create a page that allows the user to select 2 images as options, when they click one, a new page is dynamically loaded with a list of options they can choose again (like a sublevel of the image they clicked on). From there it will just continue moving down like a hierachy Can someone help me with the basic script forthis to work so i can mess with it and edit it to my needs ^ Thank you in advance Hi, I'm quite new at Javascript and I'm trying to create a script that will save me a lot of time when creating my website. I'm gonna try to explain what I'm looking for by taking a simple example. I have a page 'Portfolio'. On this page I have thumbnails of my work. 'OnMouseOver' will have the bigger version of the image appear on the screen (no need for a click). The images are named 1001, 1002, 1003, etc. The thumbs are named 1001_th, 1002_th, etc. When I click on one of the thumbnails, I want the page "Details" to open, on which only the picture and the description is different for every project. The rest of the content will be the same every time. What I am trying to do is avoid having to create a page "Details" for each one of my projects (up to 100 and growing). I figure there must be a simple solution to 'take' the number of the picture and put it in a standard "Details" page. Any help on this will be much appreciated! Thanks, M. if you take a look at this site here you can see that it no longer scrolls or even displays content, but here it does. I'll bet there's a quick fix here, but not sure what it is. Any ideas?
Hi all, am trying to create a page which will automatically scroll to the bottom, then go back to the top and start again. im very new to javascript and have done my best to peice together bits of scripts that do simular things the code below is what ive managed to come up with, it sort of works but am sure is full of mistakes Code: <SCRIPT type='text/javascript'> var CurrentScroll=0; var maxDisplacement=0; function pageReset() { CurrentScroll=0; window.scrollTo(0,0); } function pageScroll() { window.scrollTo(0,10000000); if( typeof self.pageYOffset!='undefined' ){ maxDisplacement=self.pageYOffset; } if( document.compatMode && document.compatMode != 'BackCompat' ){ maxDisplacement=document.documentElement.scrollTop ; } if( document.body && typeof(document.body.scrollTop)!='undefined' ){ maxDisplacement=document.body.scrollTop; window.scrollTo(0,0); } while(CurrentScroll <= maxDisplacement){ window.scrollBy(0,1); // horizontal and vertical scroll increments scrolldelay = setTimeout('pageScroll()',100); // scrolls every 100 milliseconds CurrentScroll = (CurrentScroll + 1); } if(CurrentScroll == maxDisplacement){ pageReset(); } } </SCRIPT> if anyone can help it would be greatly appreciated thanks in advance Scoob Hi, I have an .aspx page which the author claims to be an RSS feed (http://gcn.com/rss-feeds/state-local.aspx). It is simply a list of links with a description for each. I am trying to embed these links into an RSS feed on my own page. I am using code from http://www.mioplanet.com/rsc/newsticker_javascript.htm to create the scrolling ticker. Do I need to do something to convert the .aspx page to an RSS feed? Please help. Thanks. I've been told by many reliable sources that getting people to 'like' your site on Facebook is a great way of increasing your site traffic and getting a site ranked higher on Google and other search engines. However, it is hard work to get it implemented correctly. What you want is to have each page individually 'liked' rather than the site as a whole. To do that can take a lot of time-consuming fiddling around. We've created a simple piece of Javascript that allows you to create a custom 'like' button on each page of your site. Because we've had some help from other members with some bits and pieces of Javascript coding, it only seems fair to share something in return. Prerequisites You will need to get a Facebook Application ID from Facebook themselves. This is a unique Application ID for your domain. The easiest way to get one of these is to go to http://developers.facebook.com/docs/.../plugins/like/ and enter the details for your domain. Then click on 'GET CODE' and copy the 15 digit number from #appId. You then paste this into the Javascript as shown below. Adding the Facebook 'like' button to each page - changes to HTML In the <head> section of your HTML, add the following piece of code: Code: <script type="text/javascript" src="SocialMedia.js"></script> <script type="text/javascript"> FacebookSetup('Your page title goes here', 'image-to-show-on-Facebook.jpg'); </script> At the point on the page where you actually want the 'Like' button to appear, you then add the following piece of code: Code: <script type="text/javascript"> FacebookLike(); </script> The JavaScript Now create a JavaScript file called SocialMedia.js: Code: var facebookAppID = "xxxxxxxxxx" function FacebookSetup(title, image) { var url=window.location.host + window.location.pathname; document.write("<meta property='og:title' content='" + title + "' />"); document.write("<meta property='og:type' content='article' />"); document.write("<meta property='og:url' content='" + url + "' />"); document.write("<meta property='og:image' content='" + hostname + "/images/" + image + "' />"); document.write("<meta property='og:site_name' content='" + sitename + "' />"); document.write("<meta property='fb:admins' content='" + facebookAppID + "' />"); } function FacebookLike() { var facebook="http://www.facebook.com/plugins/like.php?href=" + url + "&layout=standard&show_faces=false&width=250&action=like&font&colorscheme=light&height=35"; document.write("<iframe src=" + facebook + " scrolling=no height=35 frameborder=0 style=border:none; overflow:hidden; width:250px; height:35px; allowTransparency=true></iframe>"); } Change the value in the variable facebookAppId on line one to your Application ID (as explained in the prerequisites section above). What happens once you've implemented this? Once you've implemented this, you should see a LIKE button on your page. If you are a Facebook user and have cookies set to always log you in, you'll find that when you click on this LIKE button, a link to your page will appear on your Facebook page, along with a thumbnail photograph as specified by you when you called FacebookSetup in your HTML code. Other people who follow you on Facebook will then also have the link to your site appearing on their News Feed. If you are not logged in when you click on the LIKE button, you will be prompted to log on to Facebook before the information appears on your News Feed. What are the benefits of using JavaScript to do this, rather than writing the HTML code for each page? Many sites have created a blanket site-wide 'LIKE' button and embedded it into their HTML. Whilst this is easy, it is limiting - the LIKE button always has the same title, the same picture and sends you to the same page on your website. Of course, it is possible to write custom HTML for each page, but this can soon get messy and then becomes more difficult to maintain. As an alternative, this JavaScript is simple and tidy. The code makes it simple to create unique Facebook 'likes' for each page, with custom text and custom images. It also keeps your HTML tidy, thereby making it easy to maintain in the future. Hope this helps, folks. I want to use javasript to create a new html page named from a text field in a form. Then I want to use javasript to copy all of the form fields to the new html page that was created using javascripting. I am creating a user are using a Javascript password login. With most of them the page is the user name or password. So this is why I am looking to do this. I use web 1000 a free host and they will only let me use javascripting. Any info or help would be great thank you
Hey, I've searched around on other forums for an answer to this but I still haven't come across an answer that works. What I want to do is go from page1 (which does not have an Iframe) to page2 (which does have an Iframe) and change the content of that Iframe based on the links clicked on page1. So say I click link1 on page1, I want page2 to show up and for the Iframe to show link1 content. If I click link2 on page1, I want page2 to show up and in the Iframe I want to see link2 content. If there's a javascript code for this that works, I would really appreciate the help. Thanks. |