JavaScript - Using Window.location To Display Content
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? Similar TutorialsCode: <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 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? 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 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. 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 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. 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???? 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 Good morning to all and thank you for sharing so much information to the non coding public. While browsing the javascriptkit.com site I came across a wonderful script to help me with pagination on a web page. The directions are simple to understand but one part has me lost. The files contentfader.js and jquery-1.2.2.pack.js are to be downloaded but where do I put them? Here is the page with the script: http://www.javascriptkit.com/script/...ntviewer.shtml I know everyone is busy and my question is basic but I have to start somewhere. Thanks, Hi, my employer found a shell html file with just a script on it as in the title PHP Code: <script type="text/javascript"> window.location="/controlPanel" </script> Can anyone tell me what this might be doing? He said he doesnt even remember uploading this file to his site. I tried googleing the code, but didn't find specifically what it is. I think maybe its a redirect of sorts, but not sure, and definately not sure why we have it or how we have it. Thanks for any help! Hello everyone! I am trying to make a article script for my website but I am facing a problem. I am almost a begginer on Javascript and PHP so I definetely need your help. I have this code that displays the title and description of three articles on each page from mysql database: Code: <?php if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; }; $start_from = ($page-1) * 3; $mysql_connection = mysql_connect("host", "user", "password") or die ('Eror: ' .mysql_error()); $database_myconnection = "database"; mysql_select_db($database_myconnection,$mysql_connection ); $sql = "SELECT * FROM tablename ORDER BY id ASC LIMIT $start_from, 3"; $rs_result = mysql_query ($sql,$mysql_connection); while ($row = mysql_fetch_assoc($rs_result)) { echo " <div> <a href=''>" .$row['title']. "</a> </div> <div style='margin-left:10px; margin-right:10px;font-family:Arial; font-style:normal; color:#000000; font-size:0.8em;'> ".$row['description']." </div> "; }; ?> </div></div> <?php $sql = "SELECT COUNT(id) FROM blog"; $rs_result = mysql_query($sql,$mysql_connection); $row = mysql_fetch_row($rs_result); $total_records = $row[0]; $total_pages = ceil($total_records / 3); for ($i=1; $i<=$total_pages; $i++) { echo "<a href='pagination.php?page=".$i."'>".$i."</a> "; }; ?> Title will be a link to the whole article but I don't want to create a new page for each article. I need that link to open a page or a new window (or something like that) where each article will be displayed. I thought that it may be possible to prearrange the content of next page or new window or popup box. Can you please help me? Thank you in advance! I can write code to open a new window and write content into that window. e.g. Code: myWin = window.open('test.csv', 'myWin', '', true); mycontent = '< ... blah ... >'; myWin.document.writeln(my_content); myWin.document.close(); Does anyone know of a way to get the browser to download the content rather than display it, using javascript? Andrew. Hi, I have popup window and i want when i press on "Clear" table content clear .. I used document.writeln to write into the popup window .. see the pic : I'm having trouble getting Google Chrome to print the correct content when I change the content of a modal page with JavaScript. This is my code: JavaScript: Code: function printCoupon(couponID) { var originalContents = document.body.innerHTML; var printable = document.getElementById(couponID); var printContents = printable.innerHTML; document.body.innerHTML = printContents; window.print(); document.body.innerHTML = originalContents; document.getElementById(couponID).scrollIntoView(true); } HTML: Code: <body> <div id="coupon1"><p>Coupon 1 contents</p></div> <div><a href="javascript:void(0)" onclick="printCoupon('coupon1');return false;">Print Coupon</a></div> <div id="coupon2"><p>Coupon 2 contents</p></div> <div><a href="javascript:void(0)" onclick="printCoupon('coupon2');return false;">Print Coupon</a></div> </body> This works in IE8 and FF 3.6, but Chrome 16 prints the original content, not the printable content. UPDATE: I just discovered another problem with this script. In IE9, the parent page is printed along with the modal (the modal looks transparent), instead of just the modal. |