JavaScript - Start Javascript From A Link?
I've just started to learn Javascript at college, and I made a little code that traps people in a dialogue box loop.
var escape = 0 for(escape === 0; escape <= 1 confirm("Going somewhere?") I want to know if there is a site, or a possibility I can start this code, simple by sending friends a URL they can click on. For completely innocent purposes, of course. Thanks! Similar TutorialsHi everyone. I'm trying to figure out how to make it so that when someone enters a number in the first textbox to start counting from and then they enter a second number where to stop counting. then the user must enter a number to step up/down by when counting.. there are 3 textboxes, one for start, one for end and one for the step up/down. When the user pushes the button the page clears and then the numbers will show.. If they use the same starting and ending number they have to be alerted that it is not valid. The user can enter a starting number bigger than the ending number. Take into account that a user might enter a positive or negative step value any tips or guidance for this is very appreciated Internet Explorer requires the user to click on an applet to activate it, which means two clicks if there is a start button, for example. I previously learned a workaround, which is to activate the applet from an external Javascript, something like this: Code: document.write('<applet code="' + appletname + '" width="' + w + '" height="' + h + '"></applet>'); This doesn't work in IE8. Is there a workaround for IE8? Thanks. Hey guys I've a download page with a button 'DOWNLOAD NOW'. When the button is clicked visitors will have to wait for the download to starts (doesn't redirect). What I want is that sometimes it takes very long for the DL to start after clicking the button, for instance 10 seconds. Hence I want to show a simple preloader WHEN the button is click, while waiting for the browser to stop loading and download to start, AND hide the preloader when browser stop loading and download started. Hi, I was wondering if there is anyone who could help me! I'm creating a Javascript slideshow, I have 'back' & 'next' functions which work. However, I'm not sure how to create a 'start' and 'stop' function (have to be separate functions), here is my current code below? IS there a genius out there who can help?! ------------------------------------------- <div id="slideshow"> <div class="mainimage"> <img height="300px" src="images/homemainimage.jpg" width="300px" height="300px" name="photoslider"/> <script language="JavaScript1.1"> var photos=new Array() var which=0 photos[0]="images/css3.svg" photos[1]="images/cloudcomputing.png" photos[2]="images/Rss.jpg" photos[3]="images/html5.png" photos[4]="images/jQuery.png" photos[5]="images/firewall.png" function swapImage(){ if (which<photos.length-1){ which++ document.images.photoslider.src=photos[which] } setTimeout("swapImage()",10000); } window.onload=swapImage; function backward(){ if (which>0){ window.status='' which-- document.images.photoslider.src=photos[which] } } function forward(){ if (which<photos.length-1){ which++ document.images.photoslider.src=photos[which] } } </script> <input type="button" value="<<Back" name="B2" onClick="backward()"> <input type="button" value="Next>>" name="B1" onClick="forward()"><br> --------------------------------------------------------- Thanks in advance!! Reply With Quote 01-20-2015, 09:56 PM #2 felgall View Profile View Forum Posts Visit Homepage Master Coder Join Date Sep 2005 Location Sydney, Australia Posts 6,745 Thanks 0 Thanked 666 Times in 655 Posts It would be easier if you used setInterval rather than setTimeout as then you just need to use clearInterval to stop and setInterval to restart. Note also that both setTimeout and setInterval expect a function as their first parameter and not a string (except for IE3) and so the way you have it coded it has to eval() the string to convert it to a function. Also the language attribute on the script tag was replaced by a type attribute about 15 years ago. Also most browsers don't allow JavaScript to access window.status any more for security reasons. 1 down vote favorite I do have the countdown script (see link below) to display the time between current time and the date given in real-time. However, I want to achieve to display the time difference between a given start and end time. Right now, it calculates from the current server time to the end time. I want to be able to set up my own start time and end time. Here is what I have: http://jsfiddle.net/BgEtE/ thank you for help Here is the code I am working with, been at it for 3 days now. I am at a loss....cant see why it shouldnt work. window.onload = defineMarquee; var timeID; var marqueeTxt = new Array(); var marqueeOff = true; function defineMarquee(){ var topValue = 0; var allElems = document.getElementsByTagName("*"); for (var i=0; i < allElems.length; i++){ if (allElems[i].className =="marqueTxt") marqueeTxt.push(allElems[i]); } for (i = 0; i < marqueeTxt.length; i++) { if (marqueeTxt[i].getComputedStyle) { topValue = marqueeTxt[i].getPropertyValue("top"); } else if (marqueeTxt[i].currentStyle) { topValue = marqueeTxt[i].currentStyle("top"); } } document.getElementById("startMarquee").onclick = startMarquee; document.getElementById("stopMarquee").onclick = stopMarquee; } function startMarquee(){ if (marqueeOff == true) { timeID = setInterval("moveMarquee()", 50); marqueeOff = false; } } function stopMarquee(){ clearInterval(timeID); marqueeOff = true; } function moveMarquee(){ var topPos = 0; for (i=0; i < marqueeTxt.length; i++){ if (marqueeTxt[i].getComputedStyle) { topPos = parseInt(marqueeTxt[i].getPropertyValue("top")); } else if (marqueeTxt[i].currentStyle) { topPos = parseInt(marqueeTxt[i].currentStyle("top")); } if (topPos < -110) { topPos = 700; } else { topPos -= 1; } marqueeTxt[i].style.top = topPos + "px"; } } Does anyone know how to make URL links that use Javascript still work when users have Javascript disabled on their browser? The only reason I'm using JS on a URL is because my link opens a PDF file, and I'm forcing it not to cache so users have the latest version. I tried the <script><noscript> tags, but I'm not sure if I'm using it correctly, as my URL completely disappears. Below is my HTML/Javascript code: <p class="download"> <script type="text/javascript">document.write("<span style=\"text-decoration: underline;\"><a href=\"javascript:void(0);\" onclick=\"window.open( 'http://www.webchild.com.au/mediakit/Direct_Media_Kit_Web.pdf?nocache='+ Math.floor( Math.random()*11 ) );\" >The Child Magazines Media Kit</a></span> (PDF 1 MB) ");</script> <noscript><span style="text-decoration: underline;"><a href="http://www.webchild.com.au/mediakit/Direct_Media_Kit_Web.pdf" >The Child Magazines Media Kit</a></span> (PDF 1 MB)</noscript> </p> Thanks for any help, Michael is it possible to link to a page and then run a javascript all in the same href? for example, i want to redirect back to the home page after a user makes a comment and show the hidden comment div this is my javascript command: Code: <a href="javascript:InsertContent('competitiveevents'); RemoveContent('stories'); InsertContent('blog-comments');"> but can i do something like this..? Code: <a href="../index.php:javascript:InsertContent('competitiveevents'); RemoveContent('stories'); InsertContent('blog-comments');"> Hi, is it possible to make a external javascript link by giving all the external links a class name then use getelementbytagname in the js file with a function to alert the hes leaving the website and let him choose if he wants to stay or leave. well thats what im trying to do but i dont know how to write the function for it maybe i could get a suggestion or a link to agood tutorial. / thanks lisa Can someone tell me how to make a close button for this? The close button I currently have here makes the IMAGE2 disappear but I cannot see IMAGE1 until the time runs out on the setTmeout. I want to be able to click the closeX and close out the whole script leaving IMAGE1 showing. Here is what I have: Code: <table border="0" width="650" id="table1" cellspacing="0" cellpadding="0" bgcolor="#000000" height="350"> <tr> <td align="center"> <script type="text/javascript"> window.onload = function () { setTimeout(function () { var div = document.getElementById('hideOverlay'); div.innerHTML = 'IMAGE1 GOES HERE'; }, 6000);} </script> <div id="hideOverlay"> <table border="0" width="650" id="table1" cellspacing="0" cellpadding="0" height="350"> <tr> <td align="center" width="650" height="350"><a style="text-decoration: none" href="javascript:void(0)" onclick="var lyr =document.getElementById('hideOverlay'); lyr.innerHTML='';"/><font color="#666666" size="2">Close [x]</font></a>IMAGE2 GOES HERE</td> </tr> </table></div> </td> </tr> </table> </div> Sup gents. Im trying to wrap some html code inside javascript. Problem is i want the picture here to link me to another page, im inserting the link command inside the picture tag put still the link isnt happening. Ive written in a wrong way? Code: document.writeln('<div id="Apartments"><table width="512" height="723" bgcolor="#666633">\n\n <tr>\n <th width="269" height="246" scope="col"><table width="243" height="208" border="1">\n <tr>\n <th height="23" colspan="2" scope="col">Apartment Fola<\/th>\n <\/tr>\n <tr>\n\n <td height="23" colspan="2"><img src="Images\/tn_G1-pokoj.jpg" alt="Fola" width="235" height="139" <a href="apartmentfola.html">/a> <\/> Hi, I'm pretty ignorant about Java and was wondering what the technique is to have different tabs for links on a page? (i.e. you can look through different categories while staying on the homepage). An example of what I mean is at the bottom of this page: http://www.huffingtonpost.com/ Any help would be much appreciated! in a javascript file that contains the following code, is there a way to hyperlink the word ELEPHANT ? $j('#message').html("white ELEPHANT"); I have a simple problem. I want to add the current page's url to a link, like this: <code> <a href="http://www.somesite.com/somepage.aspx?a="> </code> After the 'a=' I need to add javascript that will return the current url. It can be the full url (example: http://www.codingforums.com/newthrea...=newthread&f=2) or a partial one (example: /newthread.php?do=newthread&f=2). Can someone help me with an example? Sorry I am new to JavaScript. Says that a.html has two same anchor links (<a href="b.html">b</a>). The anchor links are uneditable but we could add JavaScript to the a.html. Except for dynamic adding onclick event, any other ways could get to know which anchor link being clicked? HELP NEEDED URGENTLY... Hi all, previously i posted a thread on How to HIDE a link at a certain time using javascript but now i realize i actually need the codes such that it can be implement inside the sharepoint. http://codingforums.com/showthread.p...085#post894085 One problem i encounter is that the "getElementById" is not able to control the link that i'm trying to hide. Currently what i have is this sharepoint site whereby there is a particular link that i need to hide it at a certain time and the problem now is that in sharepoint i cannot obtain the 'div id' of the control (controls refers to the combo box, text etc) in the sharepoint site. Plz help..thanks! Hi, i want to bring image download link to download a single image using like <a href="./images/sam.png">Download</a> when i click the download link it need to download plz help how can i download can finished Thanking you Hi guys I'm trying to simulate links clicking on web pages, don't know how to deal with javascript links. The link I'm trying to click contains a tag like this: <a href="javascript:function(1243423)">text</a> Would somebody help me out please? Thanks a lot Hi I'm trying to finish integrating my affiliate program and i'm having problems on the last bit.. basically how do i get this to work? basically i need the id token to be displayed... Code: <input name="radiobutton" type="radio" onclick="window.location.href='http://tracking.alpharooms.com/idevaffiliate.php?alpha_id=552&alpha_keyword= <script language="JavaScript" type="text/javascript" src="http://www.theholidaymakers.me.uk/affiliates/display.php?token=id"></script> &alpha_url=http://www.alpharooms.com/cheap-flights.aspx/?cob=64'; " value="radiobutton" /> the display.php file is below PHP Code: <?PHP ############################################################# ## iDevAffiliate Version 5.2 ## Copyright - iDevDirect.com L.L.C. ## Website: [url]http://www.idevdirect.com/[/url] ## Support: [url]http://www.idevsupport.com/[/url] ## Email: [email]support@idevdirect.com[/email] ############################################################# /* -------------------------------------------------------------- You can alter the CSS below but do not remove the Java Script Tags. They are required because this file is being called via Java Script. Any invalid coding adjustments to this page will result in Java Script errors in the page you've placed the Java Script code snippet. Adjustments to this file are not supported by iDevDirect. We highly suggest making a backup of the original display.php file before making changes. If you're wondering what the variable $idev represents, that is the affiliate ID number and is obtained from the /includes/tracking.php file. -------------------------------------------------------------- */ $token_tag_id = ""; $token_tag_username = "Affiliate Username"; $token_tag_phone = "Affiliate Phone"; $token_tag_name = "Affiliate Name"; $token_tag_company = "Affiliate Company"; $token_tag_city = "Affiliate City"; $token_tag_state = "Affiliate State"; $token_tag_zip = "Affiliate Zip Code"; $token_tag_website = "Affiliate Website"; ?> document.write('<style type="text/css">'); document.write('<!--'); document.write('p.idev {'); document.write('font-size: 12px;'); document.write('font-family: Arial, Helvetica, sans-serif;'); document.write('font-weight: bold;'); document.write('}'); document.write('-->'); document.write('</style>'); <?PHP $time_now = time(); include ("API/config.php"); include ("includes/validation_functions.php"); include ("includes/tracking.php"); // SANITIZE AND SET INCOMING TOKEN VARIABLE // ----------------------------------------------------------- $token = check_type('token'); if ($idev) { // GET AFFILIATE DATA // ----------------------------------------------------------- $aff_data = mysql_query("select username, phone, f_name, l_name, company, city, state, zip, url from idevaff_affiliates where id = '$idev'"); if (mysql_num_rows($aff_data)) { $aff_data = mysql_fetch_array($aff_data); $affiliate_username = $aff_data['username']; $affiliate_phone = $aff_data['phone']; $affiliate_fname = $aff_data['f_name']; $affiliate_lname = $aff_data['l_name']; $affiliate_name = $affiliate_fname . " " . $affiliate_lname; $affiliate_company = $aff_data['company']; $affiliate_city = $aff_data['city']; $affiliate_state = $aff_data['state']; $affiliate_zip = $aff_data['zip']; $affiliate_website = $aff_data['url']; } } // ----------------------------------------------------------- // DISPLAY TOKEN : AFFILIATE ID // ----------------------------------------------------------- if (($token == 'id') || (!$token)) { if ($idev) // ----------------------------------------------------------- { $token_id = $idev; } else { $token_id = "N/A"; } // ----------------------------------------------------------- print "document.write(\"<p class='idev'>$token_tag_id $token_id</p>\");"; } // ----------------------------------------------------------- // DISPLAY TOKEN : AFFILIATE USERNAME // ----------------------------------------------------------- if ($token == 'username') { if ($idev) // ----------------------------------------------------------- { $token_username = $affiliate_username; } else { $token_username = "N/A"; } // ----------------------------------------------------------- print "document.write(\"<p class='idev'>$token_tag_username: $token_username</p>\");"; } // ----------------------------------------------------------- // DISPLAY TOKEN : AFFILIATE PHONE // ----------------------------------------------------------- if ($token == 'phone') { if (($idev) && ($affiliate_phone)) // ----------------------------------------------------------- { $token_phone = $affiliate_phone; } else { $token_phone = "N/A"; } // ----------------------------------------------------------- print "document.write(\"<p class='idev'>$token_tag_phone: $token_phone</p>\");"; } // ----------------------------------------------------------- // DISPLAY TOKEN : AFFILIATE NAME // ----------------------------------------------------------- if ($token == 'name') { if (($idev) && ($affiliate_name)) // ----------------------------------------------------------- { $token_name = $affiliate_name; } else { $token_name = "N/A"; } // ----------------------------------------------------------- print "document.write(\"<p class='idev'>$token_tag_name: $token_name</p>\");"; } // ----------------------------------------------------------- // DISPLAY TOKEN : AFFILIATE COMPANY // ----------------------------------------------------------- if ($token == 'company') { if (($idev) && ($affiliate_company)) // ----------------------------------------------------------- { $token_company = $affiliate_company; } else { $token_company = "N/A"; } // ----------------------------------------------------------- print "document.write(\"<p class='idev'>$token_tag_company: $token_company</p>\");"; } // ----------------------------------------------------------- // DISPLAY TOKEN : AFFILIATE CITY // ----------------------------------------------------------- if ($token == 'city') { if (($idev) && ($affiliate_city)) // ----------------------------------------------------------- { $token_city = $affiliate_city; } else { $token_city = "N/A"; } // ----------------------------------------------------------- print "document.write(\"<p class='idev'>$token_tag_city: $token_city</p>\");"; } // ----------------------------------------------------------- // DISPLAY TOKEN : AFFILIATE STATE // ----------------------------------------------------------- if ($token == 'state') { if (($idev) && ($affiliate_state)) // ----------------------------------------------------------- { $token_state = $affiliate_state; } else { $token_state = "N/A"; } // ----------------------------------------------------------- print "document.write(\"<p class='idev'>$token_tag_state: $token_state</p>\");"; } // ----------------------------------------------------------- // DISPLAY TOKEN : AFFILIATE ZIP // ----------------------------------------------------------- if ($token == 'zip') { if (($idev) && ($affiliate_zip)) // ----------------------------------------------------------- { $token_zip = $affiliate_zip; } else { $token_zip = "N/A"; } // ----------------------------------------------------------- print "document.write(\"<p class='idev'>$token_tag_zip: $token_zip</p>\");"; } // ----------------------------------------------------------- // DISPLAY TOKEN : AFFILIATE WEBSITE // ----------------------------------------------------------- if ($token == 'website') { if (($idev) && ($affiliate_website) && ($affiliate_website != "http://")) // ----------------------------------------------------------- { $token_website = "<a href=\'$affiliate_website\' target=\'_blank\'>$affiliate_website</a>"; } else { $token_website = "N/A"; } // ----------------------------------------------------------- print "document.write(\"<p class='idev'>$token_tag_website: $token_website</p>\");"; } $affiliate_logo = "$logo_default"; // ----------------------------------------------------------- // DISPLAY TOKEN : AFFILIATE LOGO // ----------------------------------------------------------- if ($token == 'logo') { // ----------------------------------------------------------- // GET LOGO/IMAGE DATA // ----------------------------------------------------------- if (isset($idev)) { $logo_data = mysql_query("select filename from idevaff_logos where id = '$idev' and approved = '1'"); if (mysql_num_rows($logo_data)) { $logo_data = mysql_fetch_array($logo_data); $affiliate_logo = $logo_data['filename']; $logo_location = $base_url . "/logos/" . $affiliate_logo; } else { $logo_location = $logo_default; } } // ----------------------------------------------------------- list($width, $height, $type, $attr) = getimagesize("$logo_location"); // ----------------------------------------------------------- print "document.write(\"<img border='0' src='$logo_location' width='$width' height='$height'>\");"; } ?> HELP IS NEEDED, THANKS IN ADVANCE. Can anyone help? i'm trying to find some references and resources on how to hide a link at a certain time and show the link again at a certain time. eg: from 12pm to 2pm the link will be display, users are able to click the link. after 2pm the link will not be displayed[hide] or the when click on the link error message will be shown. plz help. thanks! |