JavaScript - Rewriting Relative Urls
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? Similar TutorialsDoing 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, 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 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 ***************************** 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 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> 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 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 I want to use a windows aero theme for each div on my page. I.e. the divs are transparent and have a blur effect to them. The only way I see to achieve this is to make the div background a blurred version of the page background and use javascript to change the div background position based on the divs position on the page. I have used the demo found here as an example, but the problem with it is that the divs background position won't sync with the page background unless the user clicks on the div and moves it slightly. This isn't a problem if the divs starting position is top left, but if you want to have it start in the center of the page initially, the divs background position is top left. How could I modify this code to move the divs background to the correct position on page load? I do not want the user to be able to drag the divs. Code: $(document).ready(function () { var dragging = true; var startX, startY, posX, posY; var window = $("#Panel1"); $("#header").mousedown(function (e) { startX = e.clientX; startY = e.clientY; posX = window.offset().left; posY = window.offset().top; console.log("X: " + e.clientX + ", Y: " + e.clientY); dragging = true; }); $(document).mousemove(function (e) { if (dragging) { moveX = e.clientX - startX; moveY = e.clientY - startY; console.log("X: " + moveX + ", Y: " + moveY); window.css({ left: posX + moveX, top: posY + moveY, "background-position": "-" + (posX + moveX) + "px -" + (posY + moveY) + "px" }); } }).mouseup(function () { dragging = false; }); }); i wanted the absolute div to be within the relative and not relative to page. when i do this without the js it works fine so something in it is making this happen. is there any way around this PLEASE HELP and THANKS! Code: <div style="position:relative"> <script type="text/javascript"> if (ie4||DOM2) document.write('<div style="position:relative"><div id="fscroller" style="position:absolute;top:0;left:0;border:0px solid black;width:'+fwidth+';height:'+fheight+'"></div></div>'); if (window.addEventListener) window.addEventListener("load", changecontent, false) else if (window.attachEvent) window.attachEvent("onload", changecontent) else if (document.getElementById) window.onload=changecontent </script> </div> Code: function changecontent(){ var index = Math.floor ( Math.random() * fcontent.length ); if (index>=fcontent.length) index=0 if (DOM2){ document.getElementById("fscroller").style.color="rgb("+startcolor[0]+", "+startcolor[1]+", "+startcolor[2]+")" document.getElementById("fscroller").innerHTML=begintag+fcontent[index]+closetag if (fadelinks) linkcolorchange(1); colorfade(1, 15); } else if (ie4) document.all.fscroller.innerHTML=begintag+fcontent[index]+closetag; index++ } Hey everyone Just throwing this out there, is it possible to have an image displayed within a canvas moves around relative to the mouse's position? For example, say I had a square canvas in the middle of the screen, and I had a small circle on that, could I have the circle position itself within the square canvas relative to the mouses position on the screen. So if my mouse was in the bottom left of the screen, the circle would be bottom left of the canvas? Thanks YD I need to find the position of an element on the page relative to the browser window. Its part of a popup calendar script (and no, they don't want to change it so please don't suggest jQuery date-picker etc) The script uses these functions http://www.mattkruse.com/javascript/...on/source.html to find the position of the anchor to pop up the calendar next to it. Now the client wants to make the calendar fixed when the user scrolls so that it always stays on screen. The most graceful solution is using css position:fixed (I'm aware it doesn't work in IE6 - that's not a problem) I've been using the getAnchorWindowPosition function to get the coordinates but the numbers its giving are wrong (to different degrees depending on the browser) It was only 200px out in the Y axis in Firefox but in IE7&8 its off the screen. I've tried googling for an answer but I can't seem to find a workable solution, mostly I've been coming up with absolute position scripts or 'just use jquery' answers. Hi. Sort of new to Javascript. I am implementing a zoom in feature, but actually tricking the user as a full screen image is simply being stretched. I plan to apply it to several pages, and don't really fancy working out the pixels for each. I believe that if you simply put width: 150% height 150% it will change the image size relative to the browser. I don't want that, I want it relative to the original image size. Could I do sort of height*1.5 or something? How would I write that if so? Thanks! Code: <script> $('#in').click(function() { $('#drag img').animate({ width: '150%', height: '150%', }, 5000, function() { // Animation complete. }); }); </script> I have the following script: Code: mytext = mytext.replace(/(\[\[(.+)\]\])/gi,"(<script src='http://www.mysite.com/mysite?Module=mymodule&Variable=$2&Output=JS'>)"); When I view the Generated Source, using Firefox Webdev plugin, it shows that the ampersands are replaced with "&", which causes the script to break. I have tried the following to no avail: Replacing the &'s with & Replacing the &'s with %26 Replacing the &'s with \u206 Placing the script in an external file Using CDATA and comments Escaping the &'s with \ before them And even unencoding them with +unencode('%26')+ Does anyone know how I can keep the &'s in the URL? Thanks in advance!!! I'm using <base href> to set my HTML path for links, and chdir() to set PHP's base path. (Entering site at www.mysite.com/account then resetting my paths back to root for simplicity). Both of these are working fine, however I've found Javascript ignores <base href> so it's working directory is still a subfolder of root. OK - so I could add '../' to all Javascript links (which is what I was trying to get away from!) but I've read that it's only IE that ignores <base href> and other browsers accept it. This will mean my links break unless I either stop using <base href> entirely and go back to using '../' in ALL links, or I can find a way to set Javascript's base link pointer... This is driving me crazy! Any ideas of how to do it? Hi Ive found out how to force another browser window to open at a certain size when a link is clicked. Here's the whole line of code including the layer, the javascript and the image, <div id="Layer6" style="position:absolute; width:10px; height:8px; z-index:6; left: 561px; top: 310px"><a href="javascript:;" onClick="MM_openBrWindow('navigation%20instructions.htm','','width=50,height=50')"><img src="images/info.gif" width="15" height="15" border="0"></a></div> How do I adapt this so I can also specify the x&y co-ordinates of the opened window relative to the window that launched it. thanks alot Masten Hi, I'm kinda hoping this is possible but haven't found any reference to it... I have a parent page that opens a popup on click that launches a sidebar navigation on the right of the screen and resizes the parent page. What I am wanting to do is create a second popup (approx 250px high) that opens below the navigation (which is only around 600px high) but I have noticed that even when you have no status bar in the popup windows, they can still end up overlapping because of additional tools or plugins that the viewer has in their browser. Is there any way to get the popups to butt up against each other instead of overlapping? More like a relative popup? Any assistance would be appreciated. :-) |