JavaScript - Loading Urls Sequentially From Arrays
I am trying to load some hundreds of urls from a local text file.
I was able to load them into an array. I want to load them sequentially after certain time interval. The script works fine if I remove setinterval but without it only 1 url gets loaded. Is there any other way to load all urls automatically 1-by-1. Here is the code: <html> <head> </head> <script type="text/javascript"> var allText =[]; var allTextLines = []; var Lines = []; var txtFile = new XMLHttpRequest(); //var i=0; txtFile.open("GET", "URL.txt", true); allText = txtFile.responseText; txtFile.onreadystatechange = function f() { if (txtFile.readyState == 4) { allText = txtFile.responseText; allTextLines = allText.split(/\r\n|\n/);//the urls are separated by /n document.write(allText); var i=Math.floor(Math.random()*100); window.location=allTextLines[i]; setInterval(f(),5000);// trying to load after 5 sec. } else { //alert("Didn't work"); } } txtFile.send(null); // <body onLoad="setInterval('f()', 30000)"> /* function onLoad(URL){ if(onLoad.loaded) window.setTimeout(f,0); else if (window.addEventListener) window.addEventListener("load",f,false); else if (window.attachEvent) window.attachEvent("onload",f); } onLoad.loaded=false; onLoad(function() { onLoad.loaded=true; }); */ </script> </html> Similar TutorialsI need to loop the alphabet and numbers 0-9 to initialize a few thousand arrays. This is for my site and is truly needed. http://www.thefreemenu.com I currently have every array written out and it takes up to much space in my .js file. The majority of my variables are empty but necessary and need to be there (including empty) for my site to work properly. Question is the last part Here's where I'm at. Code: var NewVarLetterOrNum = "a"; eval("_oneofseveralnames_" + NewVarLetterOrNum + "='this part works';"); alert(_oneofseveralnames_a); This creates the variable _oneofseveralnames_a='this part works' Code: var newArrayLetterOrNum = "a"; eval("_oneofseveralnames_" + newArrayLetterOrNum + "= new Array();"); alert(_oneofseveralnames_a) This creates the Array _oneofseveralnames_a=new Array(); and all the values in the array are null, but, now a variable like _nl_a[1]='something' can be used elsewhere because the array exists. This is all that is necessary for now because I can probably set all the variables to be blank with something like Code: i=1 while(i<=20){ _oneofseveralnames_a[i]="1-20"; i++ } alert(_oneofseveralnames_[20]); So now you have what I came to understand in the first few hours. Now to the hard part : ( I can't make multiple array's dynamically. I dont' know if its because I don't understand loops or arrays or what and its very fustrating. As for any answer you might be so kind as to provide, if you could dumb it down that would be greatly appreciated. Code: var newArray =new Array('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') i=1 while(i<=26){ eval("_nl_" + newArray[i] + "= new Array();"); i++ } alert(newArray[1]) // Is b, but alert(_nl_b) //I can't get _nl_b to exist, I tried everything including taking away the quotes around the letters in every test */ var _nl_a =new Array() var _img_a =new Array() var _h_a =new Array() var _r_a =new Array() var _m_a =new Array() var _yt_a =new Array() var _i_a =new Array() The above arrays are all the array _name_ parts I need but for example, a has 10 parts, a,p2_a,p3_a,.. p10_a. I need 10 pages for each letter of the alphabet and numbers 0-9 and a special all1, p2_all1 ... p10_all1. Overall 2200 arrays that need to be declared. Currently they are all written out. /* Hello all, I have the following code to load a new html page into the 'new content' div once the user scrolls to the bottom of the page. It all works fine. No problems, except I would like it to pause for a moment whilst it is loading, and show a loading box div at the bottom of the screen as it loads the new content, just to give some positive feedback for the user. So the new div would sit in a fixed position at 'bottom:0px;' and have a loading image inside it. Is this easy to do? I am new to javascript so bear with me Code: alreadyloading = false; nextpage = 2; $(window).scroll(function() { if($(window).scrollTop() + $(window).height() == $(document).height()) { if (alreadyloading == false) { var url = "page"+nextpage+".html"; alreadyloading = true; $.post(url, function(data) { $('#newcontent').children().last().after(data); alreadyloading = false; nextpage++; }); } } }); The 'new content' is a div which is at the bottom of the page and is where the new content loads to! Thank you very much Hello, How I open urls sequencially - one by time -, but automatically (each 5 seconds) from a list with dozens of URLs in the same iFRAME? I have what i think it is a simple question to answer. I have a button to open a new link in a iframe (in the same browser window). And what i need is that after i press the button, the link opened would come from a list of html sequencially. I dont want that the html opened would be from a random choice, but i want to be sequential. I hope that i'm being clear in my line of thought. Is this possible? cheers!!! Jan Lee At least, I think it is. On my test site (http://goo.gl/P4SLu), you'll see that the URL first goes to "emineer.com/thesis/," but then quickly changes to "emineer.com/thesis/#page=tabsservices" which refers to a piece of .js I have lower on the page (the tabbed navigation). Is there a way for me to configure this js or CSS so that the URLs are unchanged? I know it's possible because my main site functions perfectly fine: (emineer.com). The code on my main site is just clunky so I decided to start from scratch. Any help here? I'd really like my URLs clean and free of any tags or anything like that. Thanks, Brandon Doing some forum searching, I found the following code: Code: <div id="someThing" style="display:block" >Put something here.</div> <script type="text/javascript"> var nowUrl = location.href; if (nowUrl != "http://jemmakidd.com/categories.php") { document.getElementById("someThing").style.display="none"; } </script> Apparently, this is for use of when you are modifying, for example, a PHP header or footer displayed on every page and you only want something to show up on particular pages. My issue is that I am trying to put something in the header of a Tumblr blog, and I only want it to show on the post pages. The Tumblr main page format is: http://*.tumblr.com/ The Tumblr post page format is: http://*.tumblr.com/post/* Is there any code I can use to do this? Hello, I'm a complete novice in anything javascript and I've bit off more than I can chew! This script Code: function fixmenu(whichmenu) { var menu = whichmenu.find("a"); for(x = 0; x < menu.length; x++) { var o = menu.get(x); if(o.href.indexOf(".php") < 0) { var i = o.href.lastIndexOf("/"); var nl = "http://domain.com/" + o.href.substring(i + 1); o.href = nl; } } } function flinks() { fixmenu(j$("#div1")); fixmenu(j$("span#div2")); fixmenu(j$("div.div3")); } if(location.href.indexOf("sub.") >= 0 || location.href.indexOf("SUB.") >= 0) { j$(document).ready(flinks); } is not something I wrote, but something I am to make work, and I don't even know where to begin. I'm working on building a website on a custom CMS (I have no control over) and it uses relative urls (no control over that). The problem is we're integrating it with another system on subdomain. Not too sure if that makes sense. Anyways... what this is suppose to accomplish is when the website is at sub.domain.com it rewrites the relative urls in the 3 div containers to absolute urls, but ignore the links going to sub.domain.com already. In the menu (#div1) there are relative links (/page) and then there are links going to sub.domain.com/page. When we go to sub.domain.com it should rewrite the relative links (/page) to domain.com/page, but ignore sub.domain.com/page (absolute link). instead it is rewriting the entirety. Any idea as to how to make this work? I want to type urls in a text field, submit such urls and extract pictures of these web pages. Does anyone know how I can do this using javascript? Thanks, Marcelo Brazil Hello all. I am working on a userscript for a site that grabs some weather information for each NFL game. I am trying to loop GM_xmlhttpRequest(s), which has worked okay, but doesn't seem to mix well with arrays. By that I mean I am attempting to push values onto an array, but it doesn't seem to work. So basically at the bottom of the code below, I get values for wind, but not for each windArray[i]. My hunch is that has something to do with the asynchronous behavior of GM_xmlhttpRequest, but I am wondering if there is anyway around that (coding wise). I greatly appreciate any input you can provide. Code: //Strips all html elements from a string String.prototype.stripTags = function() { return this.replace(/<\/?[^>]+>|&[^;]+;|^\s+|\s+$/gi,''); } var weatherURL = new Array(); weatherURL[0] = 'http://www.nflweather.com/game/2011/week-1/bills-at-chiefs'; weatherURL[1] = 'http://www.nflweather.com/game/2011/week-1/bengals-at-browns'; weatherURL[2] = 'http://www.nflweather.com/game/2011/week-1/steelers-at-ravens'; var windArray = new Array(); function getDOC(url, callback) { GM_xmlhttpRequest({ method: 'GET', url: url, onload: function (responseDetails) { var dt = document.implementation.createDocumentType("html", "-//W3C//DTD HTML 4.01 Transitional//EN", "http://www.w3.org/TR/html4/loose.dtd"), doc = document.implementation.createDocument('', '', dt), html = doc.createElement('html'); html.innerHTML = responseDetails.responseText; doc.appendChild(html); callback(doc); } }); } for (var i=0; i<weatherURL.length; i++) { getDOC(weatherURL[i], function(doc) { var pageTds = doc.getElementsByClassName('no-line'); var wind = pageTds[9].innerHTML.stripTags(); //alert(wind); windArray.push(wind); //alert(windArray[i]); }); } I'm trying to learn how to use the url's scene7 gives me to have dynamic zoom images. The problem is I cant figure out how to load the url into a webpage instead of the browser. Here is an example image using the flyout zoom feature in scene 7. In the browser you can see the url is calling the image and the dynamic feature from scene7. How do i do this in a webpage using whatever code I need to. I've tried making it a link with an img src but that doesnt work. Im stuck and need help. Thanks for your advice. Oh, and if this is the wrong section to post in I apologize.
I got this code to WORK with Buttons... But, i can NOT get it to work with URLs/LINKs... dose anyone have any suggestions? The URL alternative LINKs are placed below the buttons... but like i have said, they don't work. Help Pleeeeese. Thanks. ****HEAD <script language="javascript" type="text/javascript"> function getCheckedValue() { document.getElementById("presentationsNavBars").style.display = 'block'; document.getElementById("proposalsNavBars").style.display = 'none'; document.getElementById("postingsNavBars").style.display = 'none'; document.getElementById("myaccountNavBars").style.display = 'none'; } function getCheckedValue2() { document.getElementById("presentationsNavBars").style.display = 'none'; document.getElementById("proposalsNavBars").style.display = 'block'; document.getElementById("postingsNavBars").style.display = 'none'; document.getElementById("myaccountNavBars").style.display = 'none'; } function getCheckedValue3() { document.getElementById("presentationsNavBars").style.display = 'none'; document.getElementById("proposalsNavBars").style.display = 'none'; document.getElementById("postingsNavBars").style.display = 'block'; document.getElementById("myaccountNavBars").style.display = 'none'; } function getCheckedValue4() { document.getElementById("presentationsNavBars").style.display = 'none'; document.getElementById("proposalsNavBars").style.display = 'none'; document.getElementById("postingsNavBars").style.display = 'none'; document.getElementById("myaccountNavBars").style.display = 'block'; } </script> ****** BODY <div class="student_text"> <asp:RadioButton ID="RadioButton1" GroupName="reg" Text="presentations" runat="server" OnClick="return getCheckedValue();" /> <br /> <%--OR how do i get it to work when using a URL as shown below for example--%> <a href="navPageTest2.aspx" runat="server" onclick="getClickedValue();">Presentations_link_ex</a><br /> </div> <br /><br /> <div class="student_text"> <asp:RadioButton ID="RadioButton2" GroupName="reg" Text="proposals" runat="server" onclick="return getCheckedValue2();" /> <br /> <%--OR how do i get it to work when using a URL as shown below for example--%> <a href="navPageTest2.aspx" onclick="getClickedValue2();">Proposals_link_ex</a><br /> </div> <br /><br /> <div class="student_text"> <asp:RadioButton ID="RadioButton3" GroupName="reg" Text="postings" runat="server" onclick="return getCheckedValue3();" /> <br /> <%--OR how do i get it to work when using a URL as shown below for example--%> <a href="navPageTest2.aspx" onclick="getClickedValue3();">Postings_link_ex</a><br /> </div> <br /><br /> <div class="student_text"> <asp:RadioButton ID="RadioButton4" GroupName="reg" Text="myaccount" runat="server" onclick="return getCheckedValue4();" /> <br /> <%--OR how do i get it to work when using a URL as shown below for example--%> <a href="navPageTest2.aspx" onclick="getClickedValue4();">Myaccount_link_ex</a><br /> </div> <br /><br /> ****************************** start display ***************************** <br /><br /> <div id="presentationsNavBars" style="display: none;"> SOME HTML HERE ..........presentations nav bar............ </div> <div id="proposalsNavBars" style="display: none;" > SOME HTML HERE 44444444 proposals nav bar 44444444444 </div> <div id="postingsNavBars" style="display: none;" > SOME HTML HERE 2222222 postings nav bar 2222222222222 </div> <div id="myaccountNavBars" style="display: block;" > SOME HTML HERE 33333333 myaccount nav bar 33333333 </div> <br /><br /> ****************************** end ***************************** Hello I am trying to create a form which when the submit button is selected will open a new window with 1 of 4 URLs based on the the combination of data in 2 select boxes. For example: if select box 1 = a and select box 2 = a then open new window with URL 1 if select box 1 = a and select box 2 = b then open new window with URL 2 if select box 1 = b and select box 2 = a then open new window with URL 3 if select box 1 = b and select box 2 = b then open new window with URL 4 Any help would be greatly appreciated. Thanks Daniel Hello, How I can detect URLs in a larger body of text using a regular expression in javascript. For ex.: I type this text in my form and I saved in database: My home page is http:// www. mypage .com.it And in my site I want to appear like he My home page is http://www.mypage.com.it Hello I am trying to create a form which when the submit button is selected will open a new window with 1 of 4 URLs based on the the combination of data in 2 select boxes. For example: if select box 1 = a and select box 2 = a then open new window with URL 1 if select box 1 = a and select box 2 = b then open new window with URL 2 if select box 1 = b and select box 2 = a then open new window with URL 3 if select box 1 = b and select box 2 = b then open new window with URL 4 Any help would be greatly appreciated. Thanks Daniel Hi there, Firstly my title may be a bit misleading as I don't i'm not sure how to do it. My situation is that I have a small piece of javascript that 'cycles' through a bunch of URL's (the URL's are reports produced by SSRS). The problem is that each time the javascript loads a new URL it has to generate the report, so I have a few seconds where the screen says 'Generating Report'. What I would like is a system that never displays the Generating Report, instead I would like to maybe pre-load the next report so it is ready to show instantly. Does anyone have any idea how to do this? Any help would be greatly appreciated. Cheers, Tom. Hi everyone, I am having trouble getting a loading bar to appear from my javascript. I have the following code in place Code: $(document).ready(function(){ $(window).scroll(function(){ var h = $('#footer').height(); var y = $(window).scrollTop(); if( y > (h*0) && y < (h*1.0) ){ $('#loading').fadeIn("slow"); $('#loading').delay(10000).fadeOut(); $("#portfolios").delay(1000).fadeIn("slow"); } }); }) I have it so when the user reacher the 'footer' div of the page, new posts appear which are contained in the 'portfolios' container div. They appear fine but no loading bar appears... The loading bar 'gif' is in the 'loading div id'. There is a 'display:none;' in the css on the loading div and the portfolios div. Any reason why the 'loading' div doesn't display but the portfolios does? I want the loading gif to show whilst the 'portfolios' is loading basically when the user hits the bottom of the page. Any help would be appreciated! Thank you! Can someone please show me a working example of how to load a WebPage from an existing WebPage using Javascript! I have tried googling the syntax and not having any luck. Thanks, Blake is there a way to after thye page load add an image. So maby loading it in the background and just showing it when you click a button?
Right, I've been searching for a few days now and i'm looking for a AJAX/JQuery script where i can load external content in to a div. I've seen a few site's that have it, and im after it so when i click the page link it loads it in the address bar like this http://www.google.co.uk/#content/index.php or what ever. Thanks. I have nearly successfully implemented a gallery using Backbox: http://www.javascriptkit.com/script/...ox/index.shtml However, when I test it in IE (7 & 8), it looks like it's invoking the javascripts and loading the large image from the thumbnail link, but then it just hangs up on the loading waiting to get the image. Does anyone know how to fix this? Thanks. The Website: http://hudson.zzl.org The CSS: http://hudson.zzl.org/galleria.classic.css The JavaScript: http://hudson.zzl.org/galleria.js The problem: a. first load = nothing shows up b. upon refresh everything loads very quickly and is fine. Ill explain my other loading problems once I can figure out how to fix this problem. Help please! |