JavaScript - Why Window.location Doesn't Work In Ff ?
dears,
am trying to redirect user from onchange event to another location in the page. its work fine in IE but not in firefox :-( why window.location doesn't work in FF ? Html: Code: <form name="forder"> <select name="bycat" onchange="gocat()"> <option value=1>one</option> <option value=2>two</option> <option value=3>three</option> </select> </form> javascript: Code: function gocat() { window.location ="index.php?show&cat=" + forder.bycat.options(forder.bycat.selectedIndex).value; } any idea???? Similar TutorialsThe photo html files on the Fanac Fan History project's website are setup to be displayed properly when JavaScript is disabled and reformatted by a php script when JavaScript is enabled. The reformatting adds some features and positions each photo's caption and credits based on the width of the photo and the browser's page width. This worked well except that, when a photo page was accessed the browser's back button wouldn't work properly. This was because I had failed to include the replace option in my windows.open statement. The statement now reads fileWindow = window.open(fileURL, "_self", "", true); and this has cured the problem with IE but it still doesn't work with FireFox. Oddly enough it worked correctly with Google's Chrome with/without the replace and with Opera and Safari it also sort of worked without the replace. With replace Opera works correctly but Safari stll needs a double click. Any suggestions? Hi there, I hope I post this in the right section. I'm trying to do a redirect using the below code: <script type="text/javascript"> window.location.href = "http://google.com" </script> FF and IE work as they should. Chrome doesn't. The request above to http://google.com, gets a 'canceled' status in Chrome browser > Development tools > "Network". I've tried several other functions: location.href = url location.replace(url) document.location = url location.assign(url) window.open(url, '_self') Same code pasted within a local html file works fine. Below is the redirect request that it's canceled by chrome: http://pastebin.com/hD36M1RG Any clues? Thanks 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. 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 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 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? 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. 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. 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. Hey guys. I'm currently paying for a web service on a hosted platform. Basically, I'm unable to edit any raw content, however I am able to do things like add JS/HTML to the header or footer of a page, which will in turn be displayed on every page of this platform. My dilemma is, I only want content being showed on a single page of the platform. Specifically, I want a window.alert being displayed on the "/signup" page, but all I have to work with is JS in a global footer. Is there some way I can use window.location to achieve this? how can you do onclick="return getconfirm('do you want to logout?');" onClick="window.location('logout.asp');" on the same button , if confirm then go url else stay here ? thank you Sorry, this is a newbie question, and probably really dumb, but... If I create a function that looks like this... Code: function recall(tim) { setTimeout("window.location.replace('somepage.html')",tim); } ...it works fine when called. However; I want to be able to pass the page url in a variable, something like this... Code: function recall(tim, myurl) { setTimeout("window.location.replace(myurl)",tim); } ...but this creates an error, saying "myurl is not defined." Even if I simplify the code and place the url in a variable within the function... Code: function recall(tim) { var myurl="somepage.html"; setTimeout("window.location.replace(myurl)",tim); } ...I still get the "myurl is not defined" error, even tho I am defining it. Plz can someone explain what I'm doing wrong. Tkx... --paul 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. EDIT: I SOLVED THIS BY USING "#" instead of "?". Thank you. Hello. My goal is to take a user's email from a form, store it in a cookie, and append it to the window location on the following page. I am doing this so that when a user shares the page with "add this widget" the stats will show me who shared the page. The problem I have is that window.location.replace("?"+ user_email); seems to be sending the browser in an infinite loop. Right now it is running as an inline function in the head. I tried calling the function with body onload and had the same problem. Code: <script = "Javascript"> (function readCookie() { var user_email = unescape(document.cookie); if (document.cookie) { window.location.replace("?"+user_email); } })(); </script> Is there another way I could achieve the same result? Thank you, Jack This is a script which has a window slide down on the page and a user can choose yes/no to continue. It works in all browsers other than IE...any help please? If you need more info, please let me know. Thanks. <script language="JavaScript" type="text/javascript"> <!-- var allowpop=1; function popWin(){ var ppl="popLayer";var objppl=findObj(ppl); if (objppl==null){return;}// if the layer does not exist, do nothing. var args=arguments,movetoX=parseInt(args[0]),movetoY=parseInt(args[1]),movespeed=parseInt(args[2]); var cycle=10,pxl=""; if(!document.layers){objppl=objppl.style;} if(objppl.tmofn!=null){clearTimeout(objppl.tmofn);} var pplcoordX=parseInt(objppl.left),pplcoordY=parseInt(objppl.top); var xX=movetoX,yY=movetoY;if((pplcoordX!=movetoX)||(pplcoordY!=movetoY)){ var moveX=((movetoX-pplcoordX)/movespeed),moveY=((movetoY-pplcoordY)/movespeed); moveX=(moveX>0)?Math.ceil(moveX):Math.floor(moveX);movetoX=pplcoordX+moveX; moveY=(moveY>0)?Math.ceil(moveY):Math.floor(moveY);movetoY=pplcoordY+moveY; if((parseInt(navigator.appVersion)>4||navigator.userAgent.indexOf("MSIE")>-1) && (!window.opera)) {pxl="px";} if (moveX!=0){eval("objppl.left='" + movetoX + pxl + "'");} if (moveY != 0) {eval("objppl.top = '" + movetoY + pxl + "'");} var sFunction = "popWin(" + xX + "," + yY + "," + movespeed+ ")"; objppl.tmofn = setTimeout(sFunction,cycle); } } function findObj(theObj, theDoc){ var p, i, foundObj; if(!theDoc) theDoc = document; if((p = theObj.indexOf("?")) > 0 && parent.frames.length) {theDoc = parent.frames[theObj.substring(p+1)].document; theObj = theObj.substring(0,p);} if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj]; for (i=0; !foundObj && i < theDoc.forms.length; i++) foundObj = theDoc.forms[i][theObj]; for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) foundObj = findObj(theObj,theDoc.layers[i].document); if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj); return foundObj; } function hideLayer(layername){ layer=findObj(layername); if(layer.style){layer=layer.style;} layer.visibility='hidden'; } // --> </script> I have a few tabs on my website. They're each set to the corresponding id in the JS file. It's supposed to add #tab-1 to the end of the URL in the users browser when it's clicked. For example, when a user is at mypage.com and they click on the tab, it ads mypage.com/#tab-1 to the end. How come it doesn't do what I want when I click it though? Here's an example of how it's setup. HTML: <a href="#tab-1" id="tab1">Text</a> JavaScript: document.getElementById("tab1").onclick = function(){ this.href += "#tab-1"; } Hi! I'm new to JavaScript and I've done some small adjustments to my clients site, but it won't show properly in IE (the shadowbox js at least.). I thought js was accepted in all newer browsers. Do you have a quick fix or idea on why it doesn't work? You can view source on my site, I use mootools, and shadowbox/corners and rightclick blocker. Is it generally a 'bad thing' to use js in webpages I want everyone to view in the same way? I tried the same effects with CSS but it's not supported in the same way corss-browser, unfortunately. The 'no selection' CSS class I have on the site is also not accepted in IE. It's very annoying! http://santinacrolla.ihaarr.com/p thank you in advance! hello... script doesn't work.. it does work in IE but not in another browser like mozilla,opera & safari? what should I do?.. Code: //Current HTML of page var html=""; //View of the page, Normal (Design), HTML, Preview var currentview=0; //Hold window objects for the color, table and properties dialogs var table_dialog, color_dialog, properties_dialog; //Current color action, ForeColor, or BackColor, //used for communication between PageCreate window and Color dialog window var pp; //Is used to disable use of design tools in HTML or Preview mode var enabletoolbar=false; //Variable counter used to index the search in the document var n=0; function InitEditor(){ //Init editor in design mode, maineditor.document.designMode=docmode; //Write a blank page WriteDefaultPage(); //Disable context menu maineditor.document.oncontextmenu=new Function("return false;"); //Set focus to the editor maineditor.focus(); } function EditorView(view){ //Changes editor view to Normal, HTML, and Preview if(currentview==1){ //If the last view was HTML then get the HTML edited by user in HTML mode html=maineditor.document.body.innerText; } //If the last mode was Normal then get the whole HTML content of the page else html=maineditor.document.all.tags("HTML")[0].outerHTML; if(view==0){ //Normal Mode EnableToolbar(true); maineditor.location="about:blank"; maineditor.document.designMode=docmode; maineditor.document.open("text/html"); maineditor.document.write(html); maineditor.document.close(); maineditor.document.oncontextmenu=new Function("return false;"); maineditor.focus(); } if(view==1){ //HTML Mode EnableToolbar(false); maineditor.location="about:blank"; maineditor.document.designMode=docmode; WriteDefaultPage(); HTMLView(); maineditor.document.oncontextmenu=new Function("return false;"); } if(view==2){ //Preview Mode EnableToolbar(false); maineditor.location="about:blank"; //Disable page editing maineditor.document.designMode="Inherit"; //Write the HTML of the page maineditor.document.open("text/html"); maineditor.document.write(html); maineditor.document.close(); //Enable context menu maineditor.document.oncontextmenu=new Function("return true;"); } //Set current view currentview=view; } function EnableToolbar(enable){ //Enable or disable toolbar enabletoolbar=enable; } function OpenFile(){ if(window.confirm("Do you want to save changes in the current document?")){ //Show Save As Dialog maineditor.document.execCommand("SaveAs"); } fileopen_dialog.style.visibility="visible"; } function OpenSelectedFile(){ //Check if the file is an HTML page if(document.fileselect.thefile.value.indexOf(".htm")==-1){ window.alert("The selected file is not an HTML page, please select a valid HTML file"); return; } //Hide the open file dialog fileopen_dialog.style.visibility="hidden"; //Create the FSO object var fso=new ActiveXObject("Scripting.FileSystemObject"); //Open the selected file var f=fso.OpenTextFile(document.fileselect.thefile.value); //Get the content of the file var thehtml=f.ReadAll(); //Close the file f.close(); //Write a blank page maineditor.window.location="about:blank"; //Write the HTML content maineditor.document.open("text/html"); maineditor.document.write(thehtml); maineditor.document.close(); //Set focus to editor maineditor.focus(); } function WriteDefaultPage(){ //Writes a blank HTML page in the editor var pagehtml="<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; " + "charset=windows-1252\">\n<meta name=\"GENERATOR\" content=\"PageCreate\">\n" + "<title>New Page</title>\n</head>\n<body>\n</body>\n</html>"; maineditor.document.open("text/html"); maineditor.document.write(pagehtml); maineditor.document.close(); } function NewPage(){ if(window.confirm("Do you want to save changes in the current document?")){ //Show Save As Dialog maineditor.document.execCommand("SaveAs"); } //Write a blank page maineditor.window.location="about:blank"; WriteDefaultPage(); //Set focus to editor maineditor.focus(); } function HTMLView(){ //Switch to HTML view maineditor.document.body.innerHTML=""; maineditor.document.body.innerText=html; } function TableOn(table, on){ //Highlights the table on which the mouse is over if(on) table.style.backgroundColor="#95AFFF"; else table.style.backgroundColor="#82DF82"; } function ToolbarOn(toolon){ //Highlights on or off the current toolbar //Get the toolbar button on which the mouse is over var tool=event.srcElement; //Change background color if(toolon){ tool.style.backgroundColor="#B4A0FE"; tool.style.borderColor="#000000"; } else{ tool.style.backgroundColor="#D1D1D1"; tool.style.borderColor="#D1D1D1"; } } function FindInPage(showdialog){ //Shows the Find and Replace Dialog var display="visible"; if(showdialog==false) display="hidden"; find_dialog.style.visibility=display; if(showdialog!=false) document.find.findwhat.focus(); } function FindIt(str, replacestr, newstr){ //This functions searchs for a string in the document //and if specified then replaces it with a new string if(str==""){ //If no string to search entered alert("Enter a string to search"); document.find.findwhat.focus(); return; } //Creates a range in the document txt = maineditor.document.body.createTextRange(); //Loop to find the string in the document for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) { txt.moveStart("character", 1); txt.moveEnd("textedit"); } if(found) { //If founded select it and scroll into view txt.moveStart("character", -1); txt.findText(str); //If replace is specified then replace the match with the new string if(replacestr) txt.text=newstr; txt.select(); txt.scrollIntoView(); n++; } else { if (n > 0) { window.alert("There are no more matches"); n=0; } // Not found anywhere, give message. else window.alert("\"" + str + "\" was not founded in document"); } } function InsertHTML(newhtml){ //Inserts HTML in the selection of the document maineditor.focus(); var selpoint=maineditor.document.selection.createRange(); selpoint.pasteHTML(newhtml); } function GetSelectedText(){ //Get the selection of the document maineditor.focus(); var selpoint=maineditor.document.selection.createRange(); var seltext=selpoint.text; return seltext; } function InsertNewImage(){ if(enabletoolbar==false) return; maineditor.focus(); //Open Insert Image Dialog maineditor.document.execCommand("insertimage", true, null); } function InsertForm(){ //Creates a new form var formmethod=window.prompt("Choose form method: GET | POST", "POST"); var formaction=window.prompt("Choose form action:", "http://"); InsertHTML("<div style=\"background-Color:#C0C0C0\"><form method=\"" + formmethod + "\" action=\"" + formaction + "\">\n<p> </p></form></div>"); } function InsertFormControl(control){ maineditor.focus(); //Inserts a form control maineditor.document.execCommand(control, true, null); } function CreateNewLink(){ //Inserts a link in the selected text if(enabletoolbar==false) return; var linktext=GetSelectedText(); if(linktext=="") return; var url=window.prompt("Enter a URL for the new link:", "http://"); if(url!=null){ InsertHTML("<a href=\"" + url + "\">" + linktext + "</a>"); } maineditor.focus(); } function InsertTable(){ //Open Table Dialog table_dialog=window.open("table.htm", "newtable", "top=100,left=100,height=300,width=400,scrollbars=no"); } function CreateTable(tr, tc, ta, tb, tp, ts, tw, tt){ //Creates a new table var tablewidth=""; if(tw!=""){ tablewidth=" width=\"" + tw + tt + "\""; } var thtml="<table border=\"" + tb + "\" cellpadding=\"" + tp + "\" cellspacing=\"" + ts + "\"" + tablewidth + ">"; tr=parseInt(tr); tc=parseInt(tc); for(r=0;r<tr;r++){ thtml+="<tr>"; for(c=0;c<tc;c++){ thtml+="<td></td>"; } thtml+="</tr>"; } thtml+="</table>"; InsertHTML(thtml); table_dialog.close(); } function EditPage(){ properties_dialog=window.open("properties.htm", "editpage", "top=100,left=100,height=275,width=387,scrollbars=no"); } function EditPageProperties(pt, pfc, pbgc, pbgi, usewatermark, pbgs){ maineditor.document.title=pt; maineditor.document.body.text=pfc; maineditor.document.body.bgColor=pbgc; maineditor.document.body.background=pbgi; if(usewatermark) maineditor.document.body.bgProperties="fixed"; else maineditor.document.body.bgProperties=""; if(pbgs!=""){ var pagehtml=maineditor.document.all.tags("HTML")[0].outerHTML; var bodytag= pagehtml.toLowerCase().indexOf("<body"); if(bodytag==-1) return; var beforebodytag= pagehtml.substring(0, bodytag); var afterbodytag= pagehtml.substring(bodytag, pagehtml.length); var pagehtml=beforebodytag + "<bgsound src=\"" + pbgs + "\">" + afterbodytag; maineditor.document.open("text/html"); maineditor.document.write(pagehtml); maineditor.document.close(); } properties_dialog.close(); maineditor.focus(); } function ChangeForeColor(){ //Show the Color dialog to edit Fore Color of text selected if(GetSelectedText()!=""){ pp="EditForeColor"; color_dialog=window.open("color.htm", "colorpicker", "top=100,left=100,height=270,width=500,scrollbars=no"); } } function EditForeColor(thecolor){ maineditor.focus(); //Change fore color of text selected maineditor.document.execCommand("forecolor", false, thecolor); //Close Color Dialog color_dialog.close(); } function ChangeBackColor(){ //Show the Color dialog to edit Back Color of text selected if(GetSelectedText()!=""){ pp="EditBackColor"; color_dialog=window.open("color.htm?p=EditBackColor", "colorpicker", "top=100,left=100,height=270,width=500,scrollbars=no"); } } function EditBackColor(thecolor){ maineditor.focus(); //Change back color of text selected maineditor.document.execCommand("backcolor", false, thecolor); //Close Color Dialog color_dialog.close(); } function ChangeFont(font){ //Changes the font of the selected text maineditor.focus(); maineditor.document.execCommand("fontname", false, font); } function ChangeFontSize(size){ //Changes the font size of the selected text maineditor.focus(); maineditor.document.execCommand("fontsize", false, size); } function DesignTools(tool){ //Activates design tool if(enabletoolbar==false){ window.alert("You must switch into normal view to do this"); return; } maineditor.focus(); maineditor.document.execCommand(tool, true, null); } Heya, I wrote the following page in a day or two (please don't mind the layout). Everything seems to work excellent, apart from in Firefox (FF) in which it doesn't seem to work at all. None of the other browsers have any trouble with it. I'm pretty new to Javascript (everything you see in the source code is pretty much all I know) and I have absolutely no idea why it doesn't work in Firefox. The page in question could be found [link has been removed]. It's all there is to it. So yeah, how to actually make this work in FF? Thanks a whole bunch in advance! Much appreciated. |