JavaScript - Location.href Misfunction
Can someone see a difference between:
<input type="submit" name="Submit" value="Start" onClick="javascript:location.href='Poll_Jan2010_01.html'"> and: <input type="submit" name="Submit" value="Next >" onClick="javascript:location.href='Poll_Jan2010_02.html'"> ??? Because the first works, but the second doesnt :/ All i wanna do is move on to the next page by clicking a submit button. From the first page it moves to second correctly. After that, it only refreshes the page and doesnt move on... Similar TutorialsHi, I'm using the following Javascript code to show a div layer depending on the URL Code: <script type="text/javascript"> if (location.href.match(/folder/)) { document.getElementById("div-layer").style.display="block"; } </script> This works perfectly when I visit http://www.domain.com/folder but I do not want it to match any subfolders beneath /folder, for example: http://www.domain.com/folder/sub-folder http://www.domain.com/folder/sub-folder2 etc. Does anyone know how I can modify the code to only match /folder or /folder/ and no subfolders beneath it? Thank you in advance. Code: <script language="JavaScript" type="text/javascript"> function confirmDelete(url){ var decision = confirm("Click OK to delete this post."); if(decision == true){ window.location = url; } } </script> <!--HTML LATER ON --> <a onclick="confirmDelete('deletePost.php?id=17')" href=''><img src='delete.png' alt='' title='Delete this post' /></a> I get absolutely nothing out of this. The confirm box pops up, but a the URL never changes when I click OK. I have no clue what's going wrong here. I'm using Google Chrome to test this out if that helps. Also does not work in Firefox. every time i try something it doesn't work for me god why is this javascript so hard to make it work... anyway, i just followed the guidelines to pass values from one page to another using ? and it simply, like always, DOES NOT work Code: <HEAD> ... ... <script type="text/javascript"> <!-- function sendme(){ if (document.form1.question[0].checked == true) { whichone = 1; } if (document.form1.question[1].checked == true) { whichone = 2; } if (document.form1.question[2].checked == true) { whichone = 3; } if (document.form1.question[3].checked == true) { whichone = 4; } if (document.form1.question[4].checked == true) { whichone = 5; } if (document.form1.question[5].checked == true) { whichone = 6; } if (document.form1.question[6].checked == true) { whichone = 7; } if (document.form1.question[7].checked == true) { whichone = 8; } myString = qst1 + "=" + whichone; location.href = "Poll_Jan2010_02.html" + '?' + myString; } //--> </script> </head> <body> <div align="center"> <p><img src="63/images/poll_logo.jpg" width="655" height="92"> </p> <p> </p> <h2><u>Question 1</u></h2> <p><strong>Bla bla bla bla...</strong></p> <form name="form1"> <table width="60%" border="0"> <tr> <td><input name="question" type="radio" value="Grill"> option 1</td> </tr> <tr> <td><input name="question" type="radio" value="Club"> option 2</td> </tr> <tr> <td><input name="question" type="radio" value="Crepes"> option 3</td> </tr> <tr> <td><input name="question" type="radio" value="Sandwiches"> option 4</td> </tr> <tr> <td><input name="question" type="radio" value="Hotdog"> option 5</td> </tr> <tr> <td><input name="question" type="radio" value="Special"> option 6</td> </tr> <tr> <td><input name="question" type="radio" value="Refreshments"> option 7</td> </tr> <tr> <td><input name="question" type="radio" value="Salads"> option 8</td> </tr> </table> </form> <p> <a href="#null" class="style2" onclick="sendme();">Continue ></a> </p> </div> </body> I guess this is an easy question for all javascripters but I don't know how to manage (I'm pretty fresh with JS). I found two solutions on this forum but it seems that they don't work(?). I want to delay for few seconds window.location.href="destination_site.html" before it will automatically take visitor to destination site. It has something to do with setTimeout but I would be greatful for posting a fixed code. Thanks in advance. This little snippet of code (in full) refuses to lnk properly in FF and Chrome, but IE downloads the file. Code: <tr> <td nowrap> <span style="font-weight: 700; font-size: 11px; background-color: #FFFF00" onclick="location.href ('http://aapress.com.au/print/headerfooteron.reg')" class="hand" onmouseover="this.style.textDecoration='underline'" onmouseout="this.style.textDecoration='none'" style="font-size: 11px; font-weight: 700; background-color:#FFFF00;"> CLICK HERE</span><font size="2"> to turn </font> <span class="hand"> <span style="font-weight: 700; font-size: 11px; background-color: #FFFF00"> ON</span></span></td> <td nowrap width="100"> </td> </tr> Is there something wrong with using location.href? Ok I have tried and tried and cannot get this code to work in safari or google chrome. Basically I am working on a shopping cart. The user will click the paypal pay now button. The form is submitted to paypal via a new window target="_blank" I also need to refresh the current page. This will write shopping cart data to DB via php upon page refresh. Safari and google Chrome will open the paypal window, but seems to ignore the javascript to refresh the browser. FF and IE both work fine. Code: <script LANGUAGE="JavaScript"> function newPage() { self.location.href=\'https://www.artists2you.com/s/orderconfirm.php?ordernumber='.$_SESSION['ordernumber'].'\'; } </script> Code: <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_blank"" onSubmit=\'newPage()\'> hi, have a series of 2 pages. The first is a drop down select box that gathers the state name. Onclick we are using a window.open to open a page with a list of cities for that state. Again using a drop down select box to select the city and then, onclick, we send the user off to the appropriate page based on state/city selection while at the same time updating the 1st (parent) page with a new location.href. Problem is that instead of updating the parent page, it updates the page with the list of cities (the child page). On the first page script we generate the following warning: Warning: XUL box for _moz_generated_content_after element contained an inline #text child, forcing all its children to be wrapped in a block. Source File: chrome://browser/content/browser.xul Line: 0 First page is not generated via javascript but standard html. This happens both locally and when pages are moved to the server (Apache). First page script is as follows Code: <HTML> <HEAD> <TITLE>J1</TITLE> <SCRIPT LANGUAGE="JavaScript"> function StateSelect (form) { Item = form.state.selectedIndex; Result = form.state.options[Item].value; window.open('j2.htm?value='+ Result,'myWindow','resizeable=no,resizeable=0,scrollbars=no,scrollbars=0,location=no,location=0,toolbar=no,toolbar=0,directories=no,directories=0,menubar=no,menubar=0,status=no,status=0,copyhistory=no,copyhistory=0,width=300,height=100,left=300,top=300,screenX=300,screenY=300') } </SCRIPT> </HEAD> 2nd page (where user selects city) code is as follows: Code: <SCRIPT LANGUAGE="JavaScript"> function CitySelect (form) { Item = form.city.selectedIndex; city = form.city.options[Item].value; state = document.myform.state.value; window.open('j3.htm','mywindow3') setTimeout("Func1()",3000); } function Func1() { parent.location.href='j4.htm?st='+ state + '&city=' + city,'mywinow2'; } </SCRIPT> Ideas on why and what the error (actually a warning) is trying to tell us? Thank you all! Jim I know next to nothing about javascript and I don't even know if this is possible. I need to target window.location.href to an iframe on a different page. So, right now, the piece of the code that redirects the browser looks like this: Code: window.location.href='http://www.somewhere.com/'; Works great, brings it up in the same browser window. So now I need to modify the code so it goes to a different page and brings that page up in a specified iframe. I hope this makes sense. I really need help. And if it is not possible, I just need to know to abandon all hope. What are the differences between results of these two. Code: window.location.hostname or Code: document.location.hostname Hi there im making a estate agency website for my college assignment and have come across a problem when using windows.location for some reason it is not working what i want to do is go to a page when searching the right content and then clicking the submit button so when i type hello for example into the text box i want to get relocated to renting1.html page but for some reason it is not working i know that the variable is set up right as if i change the content of the if statement to an alert then that works can anyone spot a problem in my code snipit <form id="form1" method="post" action="" > <label>Search House Name: <input name="Search" type="text" id="Search" size="50" /> </label> <label>Search <input type="submit" name="Search2" id="Search2" value="Submit" onclick="testResults()" /> </label> <script type="text/javascript"> function testResults() { var TestVar = form1.Search.value; if(TestVar=="hello") window.location = "renting1.html"; else alert("Invalid"); } </script> thanks for any help dave I'm trying to make a map that will show your current location, but also load an xml file to show certain attractions in your area. I have the code to work for getting your current location, but I can't figure out how to implement loading the xml file and placing markers based off of that xml file. Here is the code for getting my location: Code: function show_position(p) { document.getElementById('current').innerHTML="latitude="+p.coords.latitude.toFixed(2)+" longitude="+p.coords.longitude.toFixed(2); var pos=new google.maps.LatLng(p.coords.latitude,p.coords.longitude); map.setCenter(pos); map.setZoom(14); var infowindow = new google.maps.InfoWindow({ content: "<strong>yes</strong>" }); var marker = new google.maps.Marker({ position: pos, map: map, title:"You are here" }); google.maps.event.addListener(marker, 'click', function() { infowindow.open(map,marker); }); } </script > Can anybody help me figure this out? Thank you in advance if location is a property of window object that returns a string and im appending .indexOf() to location why is it not working?
Hi, I have a requirement of parent and child window. Onclick of a link on the parent page i am opening a child window with "window.location". On the child window i am displaying a jsp with the overlap screen on the parent screen using DOJO. After doing all the action on the child page when i am about to close the child window which is having button like cancel,close i am hiding the overlap screen. But my actual concern is when i close the child window, my parent page's scroll bar is scrolling down to the bottom of the page which should not happen and it should be there at the top of the page. How can i acheive this behaviour. Can anyone help me in this. Thanks in advance Sorry my bad, but im stuck again. I have tried to search in hours, but i cant find the answer. I think you the pro coders will see the code directly. I have an webbpage, and in the middle of it there is an iframe to a php site. So i have used this code, so after some seconds the iframe will send the guest to another page. <meta http-equiv="refresh" traget="_top" content="5 url=http://mypage.com"/> But the thing is that i want the WHOLE page to reload, and go to that page after 5 seconds (we can say). With that code, only the iframe are going to another page. Is it possible to make the whole page send the user after some seconds, to another page and not only the iframe? i need typing cursor back in first text box after clicking ok of alert [CODE] <html> <head> <script type='text/javascript'> function player() { document.getElementById("Player2").value= document.getElementById("Player1").value; } function notEmpty(elem, helperMsg){ if(elem.value.length == 0){ alert(helperMsg); elem.focus(); return false; } return true; } </script> </head> <body> <form> Player:<input type="Name" id="Player1" onkeyup="player()"/> <input type="Name" id="Player2" DISABLED /> <input type='button' onclick="notEmpty(document.getElementById('Player2'), 'Please fill in player field!')" value='Submit' /> </form> </body> </html> [ICODE] Hello In phase of my deployment I send the user a window from a servlet and inorder to communicate with an applet already loaded in another window in the browser I thought I could set the window.opener.location="${formbean.property}"; and it partly works, it get set, I see the new window flash, but it then executes that url. Two questions? 1. setting the window.opener.location in an onLoad() should not force a post back to the server, correct? I am just trying to keep that window I want up there and set an internal property so I can access the applet in the other window. Trying to make this "synthetically" a child of that page opened with the applet so I can call the applets methods simply. 2. Is there another way for a new browser window to directly access an applet in another page? I could go the route of making a probe applet and hoping they share the same JVM, (JRE1.6.0.25) access it that way. Is/how that the way to do it? Im currently creating a Table with 2 frames (table in top, last row clicked in bottom) Code: <html> <frameset rows = "60%, 40%"> <frame src = "table_driver.php" name = "A" id = "FRAME1"> <frame src = "bottom_row.php" name = "B" id = "FRAME2"> </frameset> </html> In bottom_row.php I have one object, a [obj = new TableData()]. onClick of a row in FRAME1, obj is initialized to what was clicked and the row is changed. anyways currently I have it working but want it such that it can work with multiple frames, with a location parameter. this is currently what I have Code: function TableData(headers, row, loc) { this.headerArr = headers; this.rowArr = row; this.myLoc = loc; { parent.B.document.close(); parent.B.document.open(); parent.B.document.write('<table id = "copyTable" border = "1">'); for(i=0; i<this.headerArr.length; i++) { parent.B.document.write('<tr><th>'); parent.B.document.write(this.headerArr[i]); parent.B.document.write('</th><td>'); parent.B.document.write(this.rowArr[i]); parent.B.document.write('</td></tr>'); } parent.B.document.write('</table>'); } } parent.B gets me FRAME2 and I want to either do: parent.this.myLoc parent.loc parent.myLoc but I havent had any luck with any of these. it is a javascript function any ideas? thanks! Can someone tell me how to change the following code so that it will open in a new window? (like target="_blank" in html) Code: if (phone_num=="1234") document.location="http://mysite/formgov/makeadifference.html"; I have searched for hours trying to find a solution and have tried many things, nothing has worked. The example shown above is just one of many urls that I want to change. Any help would be appreciated. Maybe this is not possible. I know nothing about javascript. We list our branches on our webpage, but I want people to be able to search for the nearest ones. This is the form I built as a place holder... but I'm sure I need a "little something" to go along with it. ha ha ha. Code: <form class="login">   <label class="white"><b>Zip Code</b><br />   <input name="zip" type="text" maxlength="5" size="10"/> </label> <br /><br /> <label>   <input type="submit" name="submit" id="submit" value="Go!" class="btn" /> </label> </form> I would like to sort them in order of closest to furthest (or even just display the top 5)... where would I find something like that? I seem to be having a difficult time with my searches in google and otherwise. Anyone have any ideas? If you go to: http://ocmd.freehostia.com/tbb/ You'll see that when the user presses enter, it goes to another page. Currently, in the scripts part of my page is this: Code: function checkKey() { if (window.event.keyCode == 13) { var audioElement = document.createElement('audio'); audioElement.setAttribute('src', 'horse.ogg'); audioElement.play(); window.location = "google.html"; return false; } } Notice how I'm trying to play an audio file? Well, I need for the window.location to go after the audio file plays, or alternatively for it to be played after xx milliseconds. Thank-you. |