JavaScript - Redirect Then Run Script Problem
Hi there, Im very new to all this and have only been working with scripts for a few days, so simple pointers would be greatly appriciated.
My problem; I play an online strategy game where i can use scripts to help my game play. There is a quick bar at the top of the game screen which i can add scripts to. When editing the bar there are 3 options. 1. Name, 2. Image URL, 3. Target URL. The script i have written is entered into the Target URL. It works fine but i have to be on a certain page in the game to run the script because of how it gets the required info. At the minute i have two scripts doing what i would like one to do. The first script (that i wrote) and a second which just redirects me to the right page (which i have to click first). Can i get both tasks on to one script. What i would like the script to do is, upon clicking redirect me to the appropriate page the script needs to be run from, and then run the javascript function. My Script; ( which isnt finished but works fine for now) Code: JavaScript: var n = prompt("1.Plunder / Looting 2. OD 3.Archer 4.Axe ", "1");n = parseInt(n); if(n == 1) {var stringOne = (document.getElementsByTagName("img")[12].title);var stringTwo = (document.getElementsByTagName("img")[10].title);var stringThree = (document.getElementsByTagName("img")[25].title);var stringFour = (document.getElementsByTagName("img")[24].title);var stringFive = stringOne + " \n" + stringTwo + " \nToday " + stringThree + " \nToday " + stringFour + "";alert (stringFive );}; if(n == 2) {var stringSix = (document.getElementsByTagName("img")[15].title);var stringSeven = (document.getElementsByTagName("img")[22].title);var stringEight = (document.getElementsByTagName("img")[23].title);var stringNine = stringSix + " \nToday as attacker " + stringSeven + " \nToday as defender " + stringEight + "";alert (stringNine );}; To sum up. Basicly i want to be able to click the link to this script and have it redirect me to the right page and then run. So where would i put the page address and how do i make the script rum when the page is loaded. Similar TutorialsHi, I want to take this redirect script and modify it so that it rotates a banner image instead of sending the user to another page. The script works so that if the window is out of focus for 10 seconds, it redirects. The images are defined in an external style sheet so I guess I'll have to move that into the document. Also, I want it to be able to work more than once with multiple images, like if the user opens a new tab, comes back, goes to a different tab, the image should change twice. Here's the script: Code: <script type="text/javascript"> var xScroll, yScroll, timerPoll, timerRedirect, timerClock; function initRedirect(){ if (typeof document.body.scrollTop != "undefined"){ //IE,NS7,Moz xScroll = document.body.scrollLeft; yScroll = document.body.scrollTop; clearInterval(timerPoll); //stop polling scroll move clearInterval(timerRedirect); //stop timed redirect timerPoll = setInterval("pollActivity()",1); //poll scrolling timerRedirect = setInterval("location.href='http://www.google.com",10000); //set timed redirect } else if (typeof window.pageYOffset != "undefined"){ //other browsers that support pageYOffset/pageXOffset instead xScroll = window.pageXOffset; yScroll = window.pageYOffset; clearInterval(timerPoll); //stop polling scroll move clearInterval(timerRedirect); //stop timed redirect timerPoll = setInterval("pollActivity()",1); //poll scrolling timerRedirect = setInterval("location.href='http://www.google.com'",10000); //set timed redirect } //else do nothing } function pollActivity(){ if ((typeof document.body.scrollTop != "undefined" && (xScroll!=document.body.scrollLeft || yScroll!=document.body.scrollTop)) //IE/NS7/Moz || (typeof window.pageYOffset != "undefined" && (xScroll!=window.pageXOffset || yScroll!=window.pageYOffset))) { //other browsers initRedirect(); //reset polling scroll position } } document.onmousemove=initRedirect; document.onclick=initRedirect; document.onkeydown=initRedirect; window.onload=initRedirect; window.onresize=initRedirect; </script> The image is defined in Code: <div id="home" style="background: url(images/banner.png) no-repeat;"></div> I'm thinking I should replace banner.png with a variable or array name that has the image names defined somewhere and using a loop to choose the next image in the array. I took a C++ class but I don't know any JS, sorry for not doing homework. Thanks for reading this Hi, I am trying to implement a script which redirects visitors to one of 24 html pages based on the hour it is when they visit. I have tried a number of other script I could find and nothing even close to working has been achieved. The pages are named: 0.html, 1.html, 2.html.....up to....22.html & 23.html I already have a simple script in use for the day of the week and am sure there must be something similar I can do for the hour of day. Any help that can be offered will be greatly appreciated as this is driving me mad. Can anyone help me out with a script that can redirect based on IP address? I want all of my computers on my LAN, 192.168.1.1-255 to be redirected to a specific page. IE When I type in test.homeip.com it goes to my web server and reads the index.html file. If the IP is in the 192.168.1.0 range it will redirect to 192.168.1.10:80 and if its any other IP it will send it to 192.168.1.11:80 Thanks! Here is what I am looking to do. I want a user to click a link and auto log into a site and then start a certain citrix app. I am not a Java programmer so my skills in this error are limited. I did put a script together that is below but it is very sloppy. It passes the credentials and logs in to Citrix and auto starts the app but it has to have two pages open to do this. Is there not a way to have Java log into a site then pass it back to the original page so it can finish the script to auto start the app. Thanks for the help. Code: <html> <head> <title>Post Page</title> <SCRIPT LANGUAGE="JavaScript"> <!-- function loginCitrix(){ go1(); go2(); } function go1() { CitrixForm.submit(); } function go2() { setTimeout('document.location="http://ctx.server1.com/Citrix/XenApp/site/launcher.aspx?CTX_Application=Citrix.MPS.App.CitrixProd.Notepad&LaunchId=1301587978804"',3000) } //--> </SCRIPT> <body onLoad="loginCitrix();"> <form method="POST" action="http://ctx.server1.com/Citrix/XenApp/auth/login.aspx" name="CitrixForm" rel="nofollow" target="_blank"><br> <input type='hidden' name='user' value='username'><br> <input type='hidden' name='password' value='password'><br> <input type='hidden' name='domain' value='corpdc'><br> <input type='hidden' name='LoginType' value='Explicit'><br> </form> </body> </html> Perhaps this wouldn't even be Javascript, but here's my question. Is there a script that would direct Opera users past the front page of a web site (that uses flash) to the home page? For instance, a site I'm building as a favor to a church has a flash intro page that is fine with every browser but Opera. (Opera doesn't respond to Autoplay but places a large "Play" button where the flash is located.) On this particular page, the flash movie ends with an "Enter" instruction and is a hyperlink to the "home" page, so if an Opera user clicks that button, they're still not going to see the flash but are going to arrive at the "home" page. Is there a way to not even present them with the flash page, but to send them straight to the home page? I'd appreciate any assistance. Friends, I am looking for a PHP or Java Script to integrete in a PHP CMS, that enables to Redirect to Another URL when the script sense that the visitor is going away from the page. (Hit back button, hit refresh button and so on....) It should be unblockable by browsers. May anyone suggest me one or share the codes. I will use it for personal purpose and not for comercial purpose at all. Thanks Hi, I am pretty much a noob when it comes to javascript. I am looking for a script that redirects random.html to 1 of 86 predefined pages, randomly. If someone could help me out, that would be great. Thanks for your help Hi, Please i am not getting clear understanding of a javascript code to redirect user to a different web page based on the day of the week. Please i have search for many script and not getting clear understanding from their code.I have also try several code myself but nothing good has come from it. Please can someone help me and write a descriptive code for me to understand better.I really plead you and your to help me...but i belief the Lord God will bless you for your time helping me. looking forward to here from you. Thank you. Clement Osei Hi guys, I have this script to print a page, which it does fine. However, after the script runs, the browser redirects to the folder root: Code: <SCRIPT Language="Javascript"> //PRINT PAGE FUNCTION function printit(){ if (window.print) { window.print() ; } else { var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>'; document.body.insertAdjacentHTML('beforeEnd', WebBrowser); WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box WebBrowser1.outerHTML = ""; } } </script> How can I stop this happening? I want remain on the current page! I've been designing a website and I recently made a few changes to it and now the home button doesnt work properly and I cant figure out why. I think it is javascript related. My problem is when you click on any category in the home page. On the next page the 'Home' link doesnt work. It clearly links back to 'index.php' but it just refreshes the page. What is even wierder is that when you try and manually retype the URL to get to index.php it still doesnt go there it just refreshes the page. I think it may be to do with a javascript redirect script I put in to prevent frames redirecting my parent window but I dont know why it causes the home link to not work properly Any ideas? To see an example of what I mean its on http://whatshalliwatch.net I need to display a receipt, open the print dialog and then go back to another form. My code is as follows at the bottom of the page: Code: <script type='text/javascript'> window.print(); window.location="newlocation"; </script> It works prefect in firefox, but not in chrome. In Chrome it just redirects and never waits for the print dialog. I need it to wait until the user can click print or cancel. If I take out the window.location line it brings up the print dialog (but I want it to redirect afterwards). Thanks to anyone who can help! I have a page up with an iframe that's approximately 300px by 405px. When I load up the site in FF and IE, it frames just fine. However, in Chrome and Opera the iframe is shifted upwards and is off-frame. I've tried looking for a solution to center the iframe correctly. Someone said to make a php code that loads 2 different iframes depending on browser (1 iframe for IE/FF and another frame for OP/CH). I have no knowledge of php coding, so I couldn't get it to work. So now, I think I'm limited to redirecting users based on browser type. If the user is using FF or IE, I'll redirect them to my original page. If they're using some other browser, I'll redirect them to a different page without the iframe. I've tried to set up a redirector, but it has trouble distinguishing between FF and Chrome. It treats them exactly the same. Does anyone have any advice on what to do? I've done tons of searching for what seems to be such a small problem. Someone please enlighten me. Hello everyone. I have a a html page that is used as a login page. I know it is not secure but this is just for learning purposes, I'm not using it for anything important. My problem is that when I put in the correct login all that happens is the page just clears the text boxes as if you were starting over. I am trying to get it to go to register.html which is located in the same directory as the login page. Help with what I'm doing wrong would be greatly appreciated. Here is the code: Code: <html> <head> <title>Login Page</title> </head> <body> <script type = "text/javascript"> var count = 2; function validate() { var un = document.myform.username.value; var pw = document.myform.pword.value; var valid = false; var unArray = ["Philip", "George", "Sarah", "Michael"]; // as many as you like - no comma after final entry var pwArray = ["Password1", "Password2", "Password3", "Password4"]; // the corresponding passwords; for (var i=0; i <unArray.length; i++) { if ((un == unArray[i]) && (pw == pwArray[i])) { valid = true; break; } } if (valid) { alert ("Login was successful"); window.location = "register.html"; return false; } var t = " tries"; if (count == 1) {t = " try"} if (count >= 1) { alert ("Invalid username and/or password. You have " + count + t + " left."); document.myform.username.value = ""; document.myform.pword.value = ""; setTimeout("document.myform.username.focus()", 25); setTimeout("document.myform.username.select()", 25); count --; } else { alert ("Still incorrect! You have no more tries left!"); document.myform.username.value = "No more tries allowed!"; document.myform.pword.value = ""; document.myform.username.disabled = true; document.myform.pword.disabled = true; return false; } } </script> <form> <table border ="5"> <tr> <th colspan="2">Login</th> </tr> <tr> <td>Username:</td> <td><input type="text" name="username" /></td> </tr> <tr> <td>Password:</td> <td><input type="password" name="pword" /></td> </tr> <tr> <th colspan="2"><input type="Submit" value="Login" name="Submit" onClick="validate()" /><input type="Reset" value="Reset" /></th> </tr> </table> <p> <a href="register.html">New users click here to register</a> </p> </form></body></html> Hi, I'm writing my first tampermonkey script, which is also my first javascript program, and I have run into a bit of a problem - can someone help? First, I'll tell say what I am trying to do and what I have done: I regularly visit a web page that has a table of text and numbers on it. I wanted to do some calculations on the numbers in each row and add a column to the table with the result of the calculation. So far so good - that works. However, the page in question has a javascript component on it that is used for sorting the table by column if the table heading is clicked on and I want the new column to behave in the same way. That bit does not work and I cannot see how to change it. The javascript in the source page looks a like this: <code> <script type='text/javascript' src='http://thesite.com/_javascript/sortable.js?2' language='javascript'></script> <script type="text/javascript"> var st = new SortableTable(document.getElementById("mytable"), ["String", "String", "Number", "None", "Number", "String", "Number", "Number"]); </script> <script type='text/javascript' src='http://thesite.com/_javascript/sortable_plus.js?2' language='javascript'></script> <script type="text/javascript"> paintTable(); </script> </code> So, I thought I might be able to edit the parameter to SortableTable() with something like this is my tampermonkey script: <code> document.body.innerHTML = document.body.innerHTML.replace('"Number", "Number"', '"Number", "Number", "Number"') </code> But that doesn't work. In fact after running that it seems that none of the table is sortable. In fact I just tested that and even if I change the text of a column heading the substitution works, but the sort routine fails, so most likely this is not the best approach. So, can anyone tell me how can I use replace the existing javascript routine or modify it so that it sorts the extra column? Thanks in advance for any assistance, Harrold Reply With Quote 01-14-2015, 10:43 PM #2 harrold View Profile View Forum Posts New to the CF scene Join Date Jan 2015 Posts 3 Thanks 0 Thanked 0 Times in 0 Posts Actually, I can see I mucked up the example replace() - but it really doesn't work even if the parameters are correct! Harrold Reply With Quote 01-16-2015, 08:10 AM #3 rnd me View Profile View Forum Posts Visit Homepage Senior Coder Join Date Jun 2007 Location Urbana Posts 4,497 Thanks 11 Thanked 603 Times in 583 Posts run the code in the script tag after you inject the new content. you might need need to add another item to the end of the column type list, looks like "Number" from here. Hello all. This script is working fine in IE7 but FF is complaining about undeclared variables. Can anybody assist to get this working in FF or do I need a new script? Any and all advice is welcome. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Test ZOOM</title> <script type="text/javascript"> //Image zoom in/out script- by javascriptkit.com //Visit JavaScript Kit (http://www.javascriptkit.com) for script //Credit must stay intact for use var zoomfactor=0.05 //Enter factor (0.05=5%) function zoomhelper(){ if (parseInt(whatcache.style.width)>10&&parseInt(whatcache.style.height)>10){ whatcache.style.width=parseInt(whatcache.style.width)+parseInt(whatcache.style.width)*zoomfactor*prefix whatcache.style.height=parseInt(whatcache.style.height)+parseInt(whatcache.style.height)*zoomfactor*prefix } } function zoom(originalW, originalH, what, state){ if (!document.all&&!document.getElementById) return whatcache=eval("document.images."+what) prefix=(state=="in")? 1 : -1 if (whatcache.style.width==""||state=="restore"){ whatcache.style.width=originalW+"px" whatcache.style.height=originalH+"px" if (state=="restore") return } else{ zoomhelper() } beginzoom=setInterval("zoomhelper()",100) } function clearzoom(){ if (window.beginzoom) clearInterval(beginzoom) } </script> </head> <body> <!-- CHANGE 99 to your image width, 100 to image height, and "office_map" to your image's name--> <a href="#" onmouseover="zoom(100,63,'office_map_6','in')" onmouseout="clearzoom()">Zoom In</a> | <a href="#" onmouseover="zoom(100,63,'office_map_6','restore')">Normal</a> | <a href="#" onmouseover="zoom(120,60,'office_map_6','out')" onmouseout="clearzoom()">Zoom Out</a> <div style="position:relative;width:420;height:300"> <div style="position:absolute"><img name="office_map_6" src="images/office_map_6.gif" width="100" height="63"> </div> </div> </body> </html> low tech I have a problem I just can't seem to solve. Seems to be an interference of two scripts. But have checked no duplicate function names or variables. Tried altering script order too. The one that breaks, breaks on this line: $('*[@title^="ajax:"]').each(function(index){ ... which I don't fully understand. The expression is a jQuery loop thing I believe. index seems to be null. I can't see where index is defined. What the code at this point aims to do is check for the phrase ajax: in all links on the page and do some manipulation so that the contents of the link are shown in a a tooltip. The problem is not about ajax. The full script is he http://www.javascriptkit.com/script/...xtooltip.shtml The problem occurs when the page includes the editor script, such as he http://www.tji-java-ide.com/beijing/...blogs&Itemid=1 The links on the top of the page work fine when there is no editor present, such as he http://www.tji-java-ide.com/beijing/...tpage&Itemid=1 confused:hope its the right place to post a newbie here . but i have a problem with a firefox accepting a script that i wrote it works on exploer but not on firefox onclick="javascript:if (this.parentNode.parentNode.nextSibling.style.display !='block') this.parentNode.parentNode.nextSibling.style.display ='block'; else this.parentNode.parentNode.nextSibling.style.display ='none';" hope u can help me thx I am working on a new site wherein i have list of links in colomn. what i want is when i click on a link. that color of the text should change to indicate that the link is selected. I am not talking about roll over effect. even after the mouse is rolls out the color should still remain as it is to show that the link is still selected. how can i do this. How can javascript detect which link is selected. and save it may be in a variable. which changes each time i select a link. what script or logic should i use for this? Thread duplicated see one above!
|