JavaScript - Execute Javascript When Browser Opens
Hi, I'm doing something wrong, I want my script to execute when the browser window opens, can someone please help me?
Code: <p><iframe id="myFrame" style="display: none;" width="500" height="300"></iframe> <script type="text/javascript">// <![CDATA[ window.onload=openpdf(); type="text/javascript">// <![CDATA[ function openPdf() { var omyFrame = document.getElementById("myFrame"); omyFrame.style.display="block"; omyFrame.src = "myFile.pdf"; } // ]]></script> Similar TutorialsHi Friends, I am facing one problem that screw me left and right. Please share me if anyone of you faced this problem and solved already. I am using the below code to assign the javascript function on select on radio button. This may vary based on radio button selection. For some radio button selection the button will be disabled. if(yes) { document.getElementById("Name").href = "javaScript:functionA()"; document.getElementById("Name").onclick = "javaScript:functionA()"; }else { document.getElementById("Name").href = "#"; } This is the code i am using to activate the button or disable the button. For some causes i am getting "javaScript:functionA()" in the address bar instead of calling that java script method. So my new window is not showing me the correct result. Please some one advise me how to solve this problem. Thanks in advance. Regards, Jeva I am wondering if its possible to execute a JavaScript script as soon as the page is loaded? Perhaps a generic execution? I tried this, but it didn't work: Code: <SCRIPT type="text/javascript"> if (document.forms["form"]["quantitym"].value > '.$row['sizem'].') { alert ("The quantity for product $row['id'] is no longer available."); } </SCRIPT> <FORM action="updatecart.html" method="post" name="form"> <DIV> <B>Medium:</B> <INPUT name="quantitym" value="'.$content['sizem'].'"> </DIV> </FORM> This is for my shopping cart system. The idea is, the customer might have 4 items in his cart, but whilst he was shopping, someone might of bought the same item, result in only 3 being available, but his cart still says 4. My solution to this is to make a script run through out his shopping when ever the cart items are listed and just prior payment execution, if the quantity he wants is no longer available, he will be alerted. $row['sizem'] is PHP drawing how many items there are from my stock database. If the value of the INPUT exceeds this availability, JavaScript shall alert. Does anyone know why it isn't alerting? Quote: Originally Posted by mlseim hmmm .... sort of stumped. For a test, I made a script that pulls a random "bumper-sticker" quote out of a file and sends it back as Javascript. Put this on a test page of yours and see what happens: <script type="text/javascript" src="http://www.catpin.com/bumper_sticker3.php"></script> Wherever that line is, when you view your web page, it should have a random quote. It's using the same code that I had above (in post #2). how would you put <script type="text/javascript" src="http://www.catpin.com/bumper_sticker3.php"></script> into a function for javascript to call this php file? Hi, I'd like to create a textarea and a division so that whatever embed code you put in the textarea it gets executed on the division in real-time. Your kind help is greatly appreciated! JavaScript newbie I wish to change the dynamic text in a javascript to that which is in a MySQL database using PHP. this is then used in a flash scroller. currently i have hard coded the text in the javascript file. is there a way to have PHP run in the javascript file before it is sent to the endusers? or another way ? First off; i was in two minds if this belonged in the .php forum or the javascript forum; i apologize if i chose the wrong one. I have this .php code: PHP Code: <?php $query = "SELECT mail_id FROM ".TBL_MAIL." WHERE UserTo = '$session->username' and status = 'unread'"; $numUnreadMail = $database->query($query) or die(mysql_error()); $numUnreadMail = mysql_num_rows($numUnreadMail); if($numUnreadMail == 0){ echo '<img src="../images/global/mail_imgs/inbox_0.png" width="22" height="15" />';} if($numUnreadMail == 1){ echo '<img src="../images/global/mail_imgs/inbox_1.png" width="22" height="15" />';} if($numUnreadMail == 2){ echo '<img src="../images/global/mail_imgs/inbox_2.png" width="22" height="15" />';} if($numUnreadMail == 3){ echo '<img src="../images/global/mail_imgs/inbox_3.png" width="22" height="15" />';} if($numUnreadMail == 4){ echo '<img src="../images/global/mail_imgs/inbox_4.png" width="22" height="15" />';} if($numUnreadMail == 5){ echo '<img src="../images/global/mail_imgs/inbox_5.png" width="22" height="15" />';} if($numUnreadMail == 6){ echo '<img src="../images/global/mail_imgs/inbox_6.png" width="22" height="15" />';} if($numUnreadMail == 7){ echo '<img src="../images/global/mail_imgs/inbox_7.png" width="22" height="15" />';} if($numUnreadMail == 8){ echo '<img src="../images/global/mail_imgs/inbox_8.png" width="22" height="15" />';} if($numUnreadMail == 9){ echo '<img src="../images/global/mail_imgs/inbox_9.png" width="22" height="15" />';} if($numUnreadMail == 10){ echo '<img src="../images/global/mail_imgs/inbox_10.png" width="22" height="15" />';} if($numUnreadMail == 11){ echo '<img src="../images/global/mail_imgs/inbox_11.png" width="22" height="15" />';} if($numUnreadMail == 12){ echo '<img src="../images/global/mail_imgs/inbox_12.png" width="22" height="15" />';} if($numUnreadMail == 13){ echo '<img src="../images/global/mail_imgs/inbox_13.png" width="22" height="15" />';} if($numUnreadMail == 14){ echo '<img src="../images/global/mail_imgs/inbox_14.png" width="22" height="15" />';} if($numUnreadMail == 15){ echo '<img src="../images/global/mail_imgs/inbox_15.png" width="22" height="15" />';} if($numUnreadMail == 16){ echo '<img src="../images/global/mail_imgs/inbox_16.png" width="22" height="15" />';} if($numUnreadMail == 17){ echo '<img src="../images/global/mail_imgs/inbox_17.png" width="22" height="15" />';} if($numUnreadMail == 18){ echo '<img src="../images/global/mail_imgs/inbox_18.png" width="22" height="15" />';} if($numUnreadMail == 19){ echo '<img src="../images/global/mail_imgs/inbox_19.png" width="22" height="15" />';} if($numUnreadMail == 20){ echo '<img src="../images/global/mail_imgs/inbox_20.png" width="22" height="15" />';} //Middle Section echo '</a> <div id="m1" onmouseover="mcancelclosetime()" onmouseout="mclosetime()">'; if($session->isAdmin()){ echo '<a href="http://localhost/admin/admin_mailinbox.php">View Inbox ';} else{ echo '<a href="http://localhost/mailinbox.php">View Inbox ';} //Displays the correct number on drop tab if($numUnreadMail == 0){ echo ' ';} if($numUnreadMail == 1){ echo '(01)';} if($numUnreadMail == 2){ echo '(02)';} if($numUnreadMail == 3){ echo '(03)';} if($numUnreadMail == 4){ echo '(04)';} if($numUnreadMail == 5){ echo '(05)';} if($numUnreadMail == 6){ echo '(06)';} if($numUnreadMail == 7){ echo '(07)';} if($numUnreadMail == 8){ echo '(08)';} if($numUnreadMail == 9){ echo '(09)';} if($numUnreadMail == 10){ echo '(10)';} if($numUnreadMail == 11){ echo '(11)';} if($numUnreadMail == 12){ echo '(12)';} if($numUnreadMail == 13){ echo '(13)';} if($numUnreadMail == 14){ echo '(14)';} if($numUnreadMail == 15){ echo '(15)';} if($numUnreadMail == 16){ echo '(16)';} if($numUnreadMail == 17){ echo '(17)';} if($numUnreadMail == 18){ echo '(18)';} if($numUnreadMail == 19){ echo '(19)';} if($numUnreadMail == 20){ echo '(20)';} ?> which displays in this navigation: <li><a href="#" onmouseover="mopen('m1')" onmouseout="mclosetime()" class="link_image"> <?php include_once('../include/mailicon_codes.php'); ?> </a> I wondered how or if it is even possible to use javascript to execute the first .php code so that the user would know if he/she had a new message without refreshing the page? Any help is greatly appreciated as i suck at .js cheers, Callum HI peers, i need to run a sql query fromjavascript onclick button and display data in a textarea . is this possible ? than you . FF, Safari, Opera all execute this javascript code to refresh the page properly, but in IE version 8.0.6001.18904 the page doesn't seem to refresh on click of orange_refresh button. I have checked out a different version of IE8, don't recall exact version, but it did seem to work fine in that one, whatever version it was probably the latest now that I think of it. Check out code below any sug.'s could be helpful, though its probably a bug.. Code: <a href="javascript:document.location.reload();" onmouseover="window.status='Refresh'; return true" onmouseout="window.status='Page Refreshed'"><img src="image/orange_refresh.png" width="30" height="30" border="0" /></a> Greetings, I am currently using the websites tutorial about browser detection using the navigator. http://www.javascriptkit.com/javatutors/navigator.shtml I am however finding myself unable to detect a pattern in order to learn from. My aim is to use Browser detection to have a CSS file for each browser type, such as Firefox, IE, Opera, Safari and then an overall CSS file if none of the above, to fix numerous flaws. For IE and Firefox using the site's code is all well and good and while I haven't tested it yet I'm wondering how to set up the coding so that it can detect a safari browser. There are lots of slashes and d's and brackets and I do find myself unable to understand their purpose. So if someone can explain how I could do it for Safari I would be very appreciative. Hello, I have a question what is the best way to identify a browser, browser version and OS in javascript. I have try a few scripts but they all fail. This will help me out formating the code for diferent browsers. Thanks Hello! I am trying to find a script that allows you to open multiple browser tabs and then close each of those tabs, either one by one or all at once. Does anyone know how to do this please? Thanks so much for your help. I have a page with categories of images. When clicked, each image on the left opens a div with it's own gallery of thumbnails. http://myspringslandscaping.com/portfolio.html Right now, to close a div, the category image has to be clicked a second time. How can I set it so that when one div opens, the other closes automatically? The client wants only one category displayed at a time. Any help would be appreciated. Thanks! Marita I can't seem to figure out what I am doing wrong. When you click the photo the script opens and then closes and never shows the slide show. Test site : http://www.royalraves.com/test/html/pets.html Blackbox.css Code: #lightbox{ position: absolute; top: 0px; left: 0; width: 100%; z-index: 100; text-align: center; } #lightbox a img{ border: none; } #outerImageContainer{ position: relative; background-color: #f7f6f1; width: 250px; height: 250px; margin: 0 auto; border: 1px #CCC solid; border-bottom:0px; } #imageContainer{ padding: 10px; } #loading{ position: absolute; top: 40%; left: 0%; height: 25%; width: 100%; text-align: center; } #hoverNav{ position: absolute; top: 0; left: 0; height: 0px; width: 0px; z-index: 0; } #imageContainer>#hoverNav{ left: 0;} #hoverNav a{ outline: none;} #prevLink, #nextLink{ width: 49%; height: 100%; background: transparent url(../images/blank.gif) no-repeat; /* Trick IE into showing hover */ display: block; } #prevLink { left: 0; float: left; } #nextLink { right: 0; float: right; } #prevLink2, #nextLink2 { font-family: Arial, Helvetica, sans-serif; font-size: 12px; color:#000; font-weight:bold; cursor:pointer; } #imageDataContainer{ font: 14px Arial, Helvetica, sans-serif; background-color: #f7f6f1; height: 35px; border:1px #ccc solid; border-top:0px; margin:auto; } #imageData{ padding:0px 10px 10px 10px; } #imageData #imageDetails{ width: 50%; float: left; text-align: left; } #imageData #caption{ font-weight: bold; font-size:11px; color:#666; max-height:20px; } #imageData #numberDisplay{ display: block; clear: left; font-weight: normal; font-size:14px; color:#333; padding-bottom: 5px; } #imageData #slideshowLink{ width: 55px; float: right; padding:5px 0px 0 0px;} #imageData #bottomNavClose{ width: 55px; float: right; padding:5px 0px 0 0px; } #overlay{ position: absolute; top: 0; left: 0; z-index: 90; width: 100%; height: 500px; background-color: #000; } .clearfix:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; } * html>body .clearfix { display: inline; width: 100%; } * html .clearfix { /* Hides from IE-mac \*/ height: 1%; /* End hide from IE-mac */ } In Head: Code: <!--- JS Code for album ---> <link rel="stylesheet" href="backbox.css" type="text/css" /> <script type="text/javascript" src="js/prototype.compressed.js"></script> <script type="text/javascript" src="js/scriptaculous.js?load=effects"></script> <script type="text/javascript" src="js/lightbox.js"></script> <script type="text/javascript" src="js/dhtmlHistory.js"></script> <script type="text/javascript" src="js/customsignsheader.js"></script> Code: For the album: <!--- Album Code for Pets ---> <div onclick="dhtmlHistory.add('location1',{message: 'backbox'});countdown()"> <a href="images/pets/7.jpg" rel="lightbox[slide]" caption="Benjamin"> <img src="images/pets/7.jpg" alt="Benjamin" width="250" height="180" border="0" /></a> </div> <a href="images/pets/1.jpg" rel="lightbox[slide]" caption="Benjamin"></a> <a href="images/pets/2.jpg" rel="lightbox[slide]" caption="Cat TV"></a> <a href="images/pets/3.jpg" rel="lightbox[slide]" caption="Hamie"></a> <a href="images/pets/4.jpg" rel="lightbox[slide]" caption="Sun Spot"></a> <a href="images/pets/5.jpg" rel="lightbox[slide]" caption="Kita"></a> <a href="images/pets/6.jpg" rel="lightbox[slide]" caption="Paws to you"></a> <a href="images/pets/7.jpg" rel="lightbox[slide]" caption="Sun Spot"></a> <a href="images/pets/8.jpg" rel="lightbox[slide]" caption="Yard Work"></a> <a href="images/pets/9.jpg" rel="lightbox[slide]" caption="Yes"></a> <a href="images/pets/10.jpg" rel="lightbox[slide]" caption="Best of Buds"></a> </center> </div> <!--- End of Album Code---> For my Javascript class, we are to take a code from the book and add on to it. In this code, I decided to add custom markers and info windows for each location. I got the info windows to work but they are the same for each marker. How can I fix this? Here is what I have: Code: <script> function init() { var myLatLng = new google.maps.LatLng(36.795209, -3.339844); var myOptions = { zoom: 2, center: myLatLng }; var map = new google.maps.Map(document.getElementById("map"), myOptions); //This is Location 1 var image = 'image1.jpg'; var canyon= new google.maps.Marker({ position: new google.maps.LatLng(35.9766,-113.7717), map: map, title:"Grand Canyon, USA"}); var infoWindow = new google.maps.InfoWindow({ content: "Grand Canyon, USA"}); google.maps.event.addListener(canyon, 'click', function(){ infoWindow.open(map, canyon); }); //This is Location 2 var image = 'image2.jpg'; var paricutin= new google.maps.Marker({ position: new google.maps.LatLng(19.5948,-102.4331), map: map, title:"Paricutin, Mexico"}); var infoWindow = new google.maps.InfoWindow({ content: "Paricutin, Mexico"}); google.maps.event.addListener(paricutin, 'click', function(){ infoWindow.open(map, paricutin); }); //This is Location 3 var image = 'image3.jpg'; var victoria= new google.maps.Marker({ position: new google.maps.LatLng(-17.928,25.826), map: map, title:"Victoria Falls, Zimbabwe"}); var infoWindow = new google.maps.InfoWindow({ content: "Victoria Falls, Zimbabwe"}); google.maps.event.addListener(victoria, 'click', function(){ infoWindow.open(map, victoria); }); //This is Location 4 var image = 'image4.jpg'; var reef= new google.maps.Marker({ position: new google.maps.LatLng(-17.98,146.76), map: map, title:"Great Barrier Reef, Austrailia"}); var infoWindow = new google.maps.InfoWindow({ content: "Great Barrier Reef, Austrailia"}); google.maps.event.addListener(reef, 'click', function(){ infoWindow.open(map, reef); }); //This is Location 5 var image = 'image5.jpg'; var harbor= new google.maps.Marker({ position: new google.maps.LatLng(-22.8424,-43.1502), map: map, title:"Harbor Rio De Janerio, Brazil"}); var infoWindow = new google.maps.InfoWindow({ content: "Harbor Rio De Janerio, Brazil"}); google.maps.event.addListener(harbor, 'click', function(){ infoWindow.open(map, harbor); }); //This is Location 6 var image = 'image6.jpg'; var everest= new google.maps.Marker({ position: new google.maps.LatLng(27.98783,86.92476), map: map, title:"Mount Everest Peak, Nepal"}); var infoWindow = new google.maps.InfoWindow({ content: "Mount Everest Peak, Nepal"}); google.maps.event.addListener(everest, 'click', function(){ infoWindow.open(map, everest); }); } google.maps.event.addDomListener(window, 'load', init); </script> I have written base rel="nofollow" target="_self" tag in head tag. It works fine in IE6 but not in IE8. window.showModalDialog() opens up new ModalDialog instead of using existing Dialog. Can anybody help me?
Hey everyone. Been racking my brain all day trying to figure out how to duplicate this code with the limited javascript knowledge I have been trying to learn. This code is a Dropdown menu of Yes or No, than a Select button that Opens up a Text Input directly below the dropdown. So far, It works great. My problem is I need at least two of these on the same page and I do not know how to go about it. I have tried changing values to accommodate adding another on the same form, but than both stop working. Can someone Please HELP! Thank you in advance. Code: <html> <head> <SCRIPT language="javascript"> function add(type) { //Create an input type dynamically. var element = document.createElement("input"); //Assign different attributes to the element. element.setAttribute("type", type); element.setAttribute("value", type); element.setAttribute("name", type); element.setAttribute("id", type); var foo = document.getElementById("fooBar"); //Append the element in page (in span). foo.appendChild(element); } </SCRIPT> </head> <body> <label> <SELECT name="element"> <OPTION value="text" name="refer_yes" id="refer_yes">Yes</OPTION> <OPTION value="text" name="refer_no" id="refer_no">No</OPTION> </SELECT> <INPUT type="button" value="Select" onclick="add(document.forms[0].element.value='')"/> </label> <span id="fooBar"> </span> </body> <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 I have code that I've been using for awhile now that will automatically log users off my site after a period of time. It works great using a 32 bit browser but not at all with a 64 bit browser. For the life of me I can't figure this out. <script type='text/javascript'> var secondsRemaining = 30; var mhcTimer; function countDown() { secondsRemaining -= 1; if (secondsRemaining <= 0) { secondsRemaining = 0; window.location='login.aspx'; } } function startAutoLogoff() { if (mhcTimer) { return false; } else { mhcTimer = setInterval('countDown();', 1000); } } startAutoLogoff(); </script> I was wondering if there was any way to determine what browser the remote address is using through JavaScript preferably or any other language and if so how to direct them to another page if they're using a specific browser...
Dear all, can somebody help me with browser compatibility and this code. Working fine in Opera and Firefox, but do not working in Internet Explorer and Chrome. With one form working fine in every browser, but when I put second form it stops to work in Explorer and Chrome. Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <HTML> <HEAD> <META http-equiv=Content-Type content="text/html; charset=UTF-8"> <SCRIPT type="text/javascript"> function showDiv(divIndex) { var f=document.forms[0]; var d=f.getElementsByTagName('div'); for(i=0;i<d.length;i++)d[i].style.display='none' d[divIndex].style.display = 'block'; } </SCRIPT> </HEAD> <BODY> <form> <select onchange="showDiv(this.value); "> <option value="0" selected>option 1</option> <option value="1">option 2</option> <option value="2">option 3</option> </select> <div style="display:block;"><form action="001.htm" method="get" > Your state<br> <select name="statecode" id="statecode"> <option value="">Choose State for option 1...</option> <option value="AK">Alaska</option> <option value="AL">Alabama</option> <option value="AR">Arkansas</option> </select> <input type="submit" name="search" value="Get Quotes" /> </form></div> <div style="display:none;"><form action="002.htm" method="get" > Your state<br> <select name="statecode" id="statecode"> <option value="">Choose State for option 2...</option> <option value="AK">California</option> <option value="AL">Colorado</option> <option value="AR">Connecticut</option> </select> <input type="submit" name="search" value="Get Quotes" /> </form></div> <div style="display:none;"><form action="003.htm" method="get" > Your state<br> <select name="statecode" id="statecode"> <option value="">Choose State for option 3...</option> <option value="AK">Massachusetts</option> <option value="AL">Maryland</option> <option value="AR">Maine</option> </select> <input type="submit" name="search" value="Get Quotes" /> </form></div> </form> </BODY></HTML> |