JavaScript - Script Not Picking Up The Url And Adding Tags
Hi,
I am using this script which is nearly working correctly, but not quite! When a user selects some text from the web-page and copies it, the script is supposed to pick up the current web-page url and create a resource box or credit line that is added to the selected text when the data is pasted. You will see that the meta keywords are used (randomly) as the anchor text and this should be wrapped with the href= tags in order to create a link. Thats the bit that is not workink, but I can not see why. Here is the complete script. Code: function init(){ // Options: var useMetaKeyword = true; // Otherwise, page title var minLength = 40; // Min selection chars var useMetaAuthor = true; // Otherwise use domain var addLinks = true; // Otherwise, just cite at end var skip = new Array("home","link","click here"); // Don't link these (lowercase!) function D(b,a,c){ if(b.addEventListener)b.addEventListener(a,c,false); else b.attachEvent&&b.attachEvent("on"+a,c)} function o(b,a){ if(typeof b=="undefined"||b==null||!RegExp)return false; a=new RegExp("(^|\\s)"+a+"(\\s|$)"); if(typeof b=="string")return a.test(b); else if(typeof b=="object"&&b.className)return a.test(b.className);return false} function E(b,a){ var c=false,j; for(j=b.parentNode;j!=undefined;){ if(b.parentNode==e.body)break; else if(b.parentNode==a){c=true;break}j=j.parentNode}return c} function F(b){ return b.replace(/^\s*/,"") } function G(b){ return b.replace(/\s*$/,"") } function H(b){ return G(F(b)) } var I=new Array("home","link","click here"), e=document, x=window, t=e.getElementsByTagName("body")[0], p=e.getElementsByName("author"), i=e.getElementsByName("keywords"), q=x.location.toString(), u=e.title.toString(), d;if(!Array.indexOf)Array.prototype.indexOf=function(b,a){ var c=-1; for(a=a|0;a<this.length||a==-1;a++) if(this[a]==b)c=a;return c}; if(i.length>0&&useMetaKeyword){ i=e.getElementsByName("keywords")[0].getAttribute("content").split(","); u=Math.floor(Math.random()*i.length); i=i[u].replace(/^\s*|\s*$/,"")} else i=u; p=(p.length>0&&useMetaAuthor)?p[0].getAttribute("content"):e.domain; var y="<p id='credit'><br/>Read more about <a href='"+q+"'>"+i+"</a> by <a href='http://"+e.domain+"' />"+p+"</a></p>"; if(/MSIE/g.test(navigator.userAgent))var v="msie"; else if(/Safari/g.test(navigator.userAgent))v="safChrome"; q=e.createElement("span");q.setAttribute("id","sasText"); t.appendChild(q); d=e.getElementById("sasText"); posType=document.all&&!window.opera&&!window.XMLHttpRequest?"absolute":"fixed"; d.style.position=posType; d.style.top="0px"; d.style.left="-9999px"; D(t,"copy",function(){d.innerHTML=y; if(v=="msie"){ for(var b=e.selection.createRange(), a=b.parentElement(); a.nodeName!="BODY"&&!o(a,"lbExclude");)a=a.parentNode; if(o(a,"lbExclude"))return true; a=e.body.createTextRange(); a.moveToElementText(d); var c=b.duplicate(); c=c.htmlText; if(c.length>minLength){ d.id="tempSasText"; d.innerHTML=c+y; (c=e.getElementById("sasText"))&&c.parentNode.removeChild(c); d.id="sasText";a.select()}} else{b=x.getSelection(); for(a=b.anchorNode;a.nodeName!="BODY"&&!o(a,"lbExclude");)a=a.parentNode; if(o(a,"lbExclude"))return false; if(b==""&&v=="safChrome"){ d.innerHTML=t.innerHTML; a=document.createRange(); b.removeAllRanges(); a.selectNodeContents(d);b.addRange(a)} else if(b.toString().length>minLength){ var j=e.getElementById("credit"); a=b.getRangeAt(0); c=a.cloneContents(); d.id="tempSasText"; d.insertBefore(c,j); (c=e.getElementById("sasText"))&&c.parentNode.removeChild(c); d.id="sasText"; b.removeAllRanges(); a.selectNode(d); b.addRange(a)}} var w=[];a=d.getElementsByTagName("a");for(b=0;b<a.length;b++)w.push(a[b].href); if(addLinks){a=e.getElementsByTagName("a"); for(b=0;b<a.length;b++){var r=a[b].href; if(w.indexOf(r)==-1)if(E(a[b],d)==false){ var f=H(a[b].innerHTML).toLowerCase(); if(skip.indexOf(f)==-1) if((new RegExp(e.domain,"g")).test(r)){ var z=[]; function n(g,k,l){ for(var A=g.childNodes.length;A-- >0;){ var h=g.childNodes[A]; if(h.nodeType===1)h.tagName.toLowerCase()!=="a"&&n(h,k,l); else if(h.nodeType===3) for(var m=h.data.length;1;){ m=h.data.lastIndexOf(k,m); if(m===-1||z.indexOf(k.toLowerCase())!==-1)break; var B=/\w/; if(h.nodeValue.charAt(m-1).match(B)||h.nodeValue.charAt(m+f.length).match(B))break; l.call(window,h,m)}}} function s(g,k){g.splitText(k+f.length); var l=e.createElement("a"); l.href=r;l.appendChild(g.splitText(k)); g.parentNode.insertBefore(l,g.nextSibling); z.push(f.toLowerCase()); w.push(r)}n(d,f,s);f=f.charAt(0).toUpperCase()+f.slice(1);n(d,f,s); f=f.toUpperCase(); n(d,f,s);f=f.replace(/\w\S*/g,function(g){ return g.charAt(0).toUpperCase()+g.substr(1).toLowerCase()});n(d,f,s)}}}}})} window.onload=init; I have put the script on this page: test page To test it, just go to that page, highlight some text (at least 40 characters) copy it, and then paste it into your editor or notepad. You can see that it is picking up some info and writing the attribute line but it doesn't create the link If it helps get it working, I am happy to slim the code down by excluding some features. Any ideas ? Similar TutorialsHi, I have a regular expression which removes anything between <script> and </script> tags. The problem comes when there is more than one on a page, eg. Code: <script>lose this</script> content I want to keep <script>lose this</script> Everything in that string is removed... how can I limit it to complete tags only? I did a search but could only find ones that either remove tags only, or have the same problem as mine. Cheers, Gus Hi All, I'd be truly grateful if anyone can help me (a not so good JavaScripter). I'm trying to adapt some code. I have 3 chained select boxes which when the third is selected, I'd like to display specific info from the array within the HTML via the 'info' div. It works, but displays the whole array entry, and I'd just like to pick certain info from that entry. You can see my efforts within the 'categories["Nonfiction"]' entry - I've added the extra array elements to add another dimension to the array, but I think I've got into a muddle - can anyone help? So... when a user selects BOOKS > NONFICTION > COOKBOOKS I'd like just the 'Extra info 01' & 'Extra info 02' text to appear within the 'info' div. 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> <title>Interdependent Select Menus</title> <script type="text/javascript"> var categories = []; categories["startList"] = ["Books", "Clothes"]; categories["Books"] = ["Biography","Fiction","Nonfiction"]; categories["Biography"] = ["Contemporay","Historical","Other"]; categories["Fiction"] = ["Science Fiction","Romance", "Thrillers", "Crime"]; categories["Nonfiction"] = [["How-To", "Extra info 01", "Extra info 02"], ["Cookbooks", "Extra info 01", "Extra info 02"], ["Travel", "Extra info 01", "Extra info 02"] ]; categories["Clothes"] = ["Men","Women","Children"]; categories["Men"] = ["Shirts","Ties","Belts","Hats"]; categories["Women"] = ["Blouses","Skirts","Scarves", "Hats"]; categories["Children"] = ["Shorts", "Socks", "Coats", "Nightwear"]; var nLists = 3; // number of select lists in the set function fillSelect(currCat,currList){ var step = Number(currList.name.replace(/\D/g,"")); for (i=step; i<nLists+1; i++) { document.forms['tripleplay']['List'+i].length = 1; document.forms['tripleplay']['List'+i].selectedIndex = 0; } var nCat = categories[currCat]; for (each in nCat) { var nOption = document.createElement('option'); var nData = document.createTextNode(nCat[each]); nOption.setAttribute('value',nCat[each]); nOption.appendChild(nData); currList.appendChild(nOption); } } function getValue(L3, L2, L1) { document.getElementById("info").innerHTML = L1 + "\n" + L2 + "\n" + L3; } function init() { fillSelect('startList',document.forms['tripleplay']['List1']) } navigator.appName == "Microsoft Internet Explorer" ? attachEvent('onload', init, false) : addEventListener('load', init, false); </script> </head> <body> <form name="tripleplay" action=""> <select name='List1' onchange="fillSelect(this.value,this.form['List2'])"> <option selected>Make a selection</option> </select> <br /> <select name='List2' onchange="fillSelect(this.value,this.form['List3'])"> <option selected>Make a selection</option> </select> <br /> <select name='List3' onchange="getValue(this.value, this.form['List2'].value, this.form['List1'].value)"> <option selected >Make a selection</option> </select> <div id="info">This is the default text</div> </form> </body> </html> I have placed the <script></script> in the <head></head> tags and the page will not work. But placing the <script> below the element that the JS works with allows the page to work but thought the correct method to use was place all JS functions inside the <head> tags? here is a link to the folder I am testing this out on. http://www.realistichostings.com/test_booking/ I have named the two files accordingly, test_booking_page-script is in head tags.php test_booking_page-script is outside head tags.php can anyone tell me why the code works outside the head tag but not when i is inside the head tag ? Hi, Right I have a bit of a beginners problem, I am a designer and previously had a little HTML knowledge, I am working for a charity and have picked up their website, http://www.2learn.org.uk They had a drop down menu in place, which I would now like to change. I want to learn how to edit items within the code, delete add and change. I have tried to understand and manipulate the code but as I have not worked with javascript except copying sample code or basic stuff in BlueJ years ago that I forget. What do I need to do in order to get this sorted can anyone help, sorry if this is a bit vague but I'm not sure where to start. I could liase with someone with the code, call it pro boner work for yourselves. Thanks Tom i have been experimenting on this...i don't know why this happens i am sure there is something wrong with my javascript code this is what happens... Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <script language="Javascript" type="text/javascript"> function addRow() { // grab the element, i.e. the table your editing, in this we're calling it // 'mySampleTable' and it is reffered to in the table further down on the page // with a unique of id of you guessed it, 'mySampleTable' var tbl = document.getElementById('mySampleTable'); // grab how many rows are in the table var lastRow = tbl.rows.length; // if there's no header row in the table (there should be, code at least one //manually!), then iteration = lastRow + 1 var iteration = lastRow; // creates a new row var row = tbl.insertRow(lastRow); // left cell // insert a cell // var cellLeft = row.insertCell(0); // here we're just using numbering the cell, like anything else you don't // have to use this, but i've kinda noticed users tend to like them // var textNode = document.createTextNode(iteration); // takes what we did (create the plain text number) and appends it the cell // we created in the row we created. NEAT! //cellLeft.appendChild(textNode); // right cell // another cell! var cellRight = row.insertCell(1); // creating an element this time, specifically an input var el = document.createElement('input'); // a data type of text el.type = 'text'; // the name of the element txtRow, and because this is dynamic we also // append the row number to it, so for example if this is the eigth row // being created the text box will have the name of txtRow8. super fantastic. el.name = 'txtRow' + iteration; // the exact same thing with a unique id el.id = 'txtRow' + iteration; // set it to size of 40. setting sizes is good. el.size = 40; // same thing as earlier, append our element to our freshly and clean cell cellRight.appendChild(el); // select cell // our last cell! var cellRightSel = row.insertCell(0); // create another element, this time a select box var sel = document.createElement('select'); // name it, once again with an iteration (selRow8 using the example above) sel.name = 'selRow' + iteration; // crates options in an array // the Option() function takes the first parameter of what is being displayed // from within the drop down, and the second parameter of the value it is carrying over sel.options[0] = new Option('text zero', 'value0'); sel.options[1] = new Option('text one', 'value1'); sel.options[2] = new Option('text two', 'value2'); // append our new element containing new options to our new cell cellRightSel.appendChild(sel); el.size = 40; } function removeRow() { // grab the element again! var tbl = document.getElementById('mySampleTable'); // grab the length! var lastRow = tbl.rows.length; // delete the last row if there is more than one row! if (lastRow > 2) tbl.deleteRow(lastRow - 1); } </script> <html> <head> <title>Page Title</title> </head> <body leftmargin="0" topmargin="0"> <form action="addrow.html" name="eval_edit" method="post" format="html"> <table align="center" width = "75%"> <tr> <td align = "center"> click add to you know, add a row, and remove to remove a row, and submit to submit your page! whee! </td> </tr> <tr> <td align = "center"> <!--- very imporant to give the table an id ---> <!--- otherwise it won't know where to edit ---> <table border="1" id="mySampleTable"> <tr> <td> Type of Leave </td> <td> No. of Days allowed </td> </tr> <!--- i create the initial row by hand, there are a lot of ---> <!--- different ways to do this depending on what parsing ---> <!--- language you use, i found this was easiest for the ---> <!--- snippet, but experiment, do your thing mang. ---> <!--- this matches the same specs we laid out in the javascript ---> <tr> <td><select name="selRow0"> <option value="value0">text zero</option> <option value="value1">text one</option> <option value="value2">text two</option> </select> </td> <td> <input type="text" name="txtRow1" id="txtRow1" size="40" /> </td> </tr> </table> <!--- our buttons call our javascript functions when clicked ---> <input type="button" value="Add" onclick="addRow();" /> <input type="button" value="Remove" onclick="removeRow();" /> <input type="submit" value="Submit" /> </td> </tr> </table> </form> </body> </html> Hi, I want to add a cookie in this script to show the popunder once a day. Can someone help me to change the following code to make it work ? Code: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Popunder</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> </head> <body> <form id="popSubmit" action="http://www.google.com"> <input type="submit" /> </form> <script type="text/javascript"> (function($) { $.popunder = function(sUrl) { var _parent = self; var bPopunder = ($.browser.msie && parseInt($.browser.version, 10) < 9); if (top != self) { try { if (top.document.location.toString()) { _parent = top; } } catch(err) { } } var sOptions = 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=0,resizable=1,width=' + (screen.availWidth).toString(); sOptions += ',height=' + (screen.availHeight).toString() + ',screenX=0,screenY=0,left=0,top=0'; var popunder = _parent.window.open(sUrl, 'pu_' + Math.floor(89999999*Math.random()+10000000), sOptions); if (popunder) { popunder.blur(); if (bPopunder) { window.focus(); try { opener.window.focus(); } catch (err) { } } else { popunder.init = function(e) { with (e) { (function() { if (typeof window.mozPaintCount != 'undefined') { var x = window.open('about:blank'); x.close(); } try { opener.window.focus(); } catch (err) { } })(); } }; popunder.params = { url: sUrl }; popunder.init(popunder); } } return this; } })(jQuery); $('#popSubmit').submit(function() { jQuery.popunder('http://www.facebook.com'); }); </script> </body> </html> I have no idea what to change in order to do this so I'm hoping someone can help Basically this is a menu I have which I'm using in wordpress. Wordpress puts 'current' on the current page, so the menu knows which list item to keep highlighted. On one of my pages however, it is hidden from the menu, therefor NONE of the list items contain 'current'. It makes the menu look bad when you are on this page. What I'd like to do to this code, is add a very small feature that checks if none of the list items have 'current'. If none of the li's contain current, then just apply it to li:first-child (which is my home button). I'm not familiar with javascript, but I feel that would be doable from just the script that I'm pasting below. Code: /** * LavaLamp - A menu plugin for jQuery with cool hover effects. * @requires jQuery v1.1.3.1 or above * * http://gmarwaha.com/blog/?p=7 * * Copyright (c) 2007 Ganeshji Marwaha (gmarwaha.com) * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * * Version: 0.2.0 * Requires Jquery 1.2.1 from version 0.2.0 onwards. * For jquery 1.1.x, use version 0.1.0 of lavalamp */ (function(jQuery) { jQuery.fn.lavaLamp = function(o) { o = jQuery.extend({ fx: "linear", speed: 500, click: function(){} }, o || {}); return this.each(function() { var me = jQuery(this), noop = function(){}, jQueryback = jQuery('<li class="back"><div class="left"></div></li>').appendTo(me), jQueryli = jQuery("li", this), curr = jQuery("li.current", this)[0] || false; if (curr == false){jQuery(".back").remove();return false;} jQueryli.not(".back").not("#nav ul li").hover(function() { move(this); }, noop); jQuery(this).hover(noop, function() { move(curr); }); jQueryli.click(function(e) { setCurr(this); return o.click.apply(this, [e, this]); }); setCurr(curr); function setCurr(el) { jQueryback.css({ "left": el.offsetLeft+"px", "width": el.offsetWidth+"px" }); curr = el; }; function move(el) { jQueryback.each(function() { jQuery(this).dequeue(); } ).animate({ width: el.offsetWidth, left: el.offsetLeft }, o.speed, o.fx); }; }); }; })(jQuery); Hello - I'm trying to add a fade effect between slideshow transitions. The script I'm building from is the Rich HTML Slideshow script which appears below. The slides that rotate are wrapped in <div> tags with a class of "dyncontent" and I've managed to make the slideshow transition just fine, but not with any kind of fade effect. It just "snaps" from one slide to the next. Is this a fairly simple addition? Thanks! <script type="text/javascript"> if (document.all || document.getElementById){ //if IE4 or NS6+ document.write('<style type="text/css">\n') document.write('.dyncontent{display: none; width: 250px; height: 60px;}\n') document.write('</style>') } var curcontentindex=0 var messages=new Array() function getElementByClass(classname){ var inc=0 var alltags=document.all? document.all : document.getElementsByTagName("*") for (i=0; i<alltags.length; i++){ if (alltags[i].className==classname) messages[inc++]=alltags[i] } } function rotatecontent(){ //get current message index (to show it): curcontentindex=(curcontentindex<messages.length-1)? curcontentindex+1 : 0 //get previous message index (to hide it): prevcontentindex=(curcontentindex==0)? messages.length-1 : curcontentindex-1 messages[prevcontentindex].style.display="none" //hide previous message messages[curcontentindex].style.display="block" //show current message } window.onload=function(){ if (document.all || document.getElementById){ getElementByClass("dyncontent") setInterval("rotatecontent()", 2000) } } </script> Hello Everyone, I am in the process of creating a billboard script for our company front page which will switch between two images. I am using the following script as a base: http://tympanus.net/codrops/2009/12/...query-and-css/ I am eager to learn coding, but am still a novice at it so I was wondering if anyone could assist me with adding the following functionality: 1. Rather than (or perhaps in addition to) having the two images change based on a timer, I'd like to be able to insert a "next" arrow. Therefore I will need assistance in coding a button to change the images from "ad_1" to "ad_2" which is currently done automatically by the interval timer 2. I'd like to make the images clickable with unique destinations (so when you click on "ad_1" it will take you to "link 1", "ad_2" will take you to "link 2" Below is my current code: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>Rotating Billboard with jQuery</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8"/> </head> <body> <div class="palmtrees"></div> <div class="powerline"></div> <div class="city"></div> <div class="container"> <div class="ad"> <div id="ad_1" class="ad_1"> <img class="slice_1" src="ads/ad1_slice01.jpg"/> <img class="slice_2" src="ads/ad1_slice02.jpg"/> <img class="slice_3" src="ads/ad1_slice03.jpg"/> </div> <div id="ad_2" class="ad_2"> <img class="slice_1" src="ads/ad2_slice01.jpg"/> <img class="slice_2" src="ads/ad2_slice02.jpg"/> <img class="slice_3" src="ads/ad2_slice03.jpg"/> </div> </div> </div> <div class="billboard"></div> <a class="back" href="http://tympanus.net/codrops/2009/12/16/creating-a-rotating-billboard-system-with-jquery-and-css/"><a> <script src="jquery-1.3.2.js" type="text/javascript"></script> <script> $(function() { $('#ad_1 > img').each(function(i,e){ rotate($(this),500,10000,i); }); function rotate(elem1,speed,timeout,i){ elem1.animate({'marginLeft':'18px','width':'0px'},speed,function(){ var other; if(elem1.parent().attr('id') == 'ad_1') other = $('#ad_2').children('img').eq(i); else other = $('#ad_1').children('img').eq(i); other.animate({'marginLeft':'0px','width':'266px'},speed,function(){ var f = function() { rotate(other,speed,timeout,i) }; setTimeout(f,timeout); }); }); } }); </script> </body> </html> And here is a working example: http://www.santamarinas.com/RS/Tests/Billboard/ Thank you in advance for your help!! I want to insert this star trail effect script to page below but star trail doesn't appear on most areas and script corrupts several objects' position. How can I insert it successfully? http://www.orkinosfilm.com/melissa/index.html Code: <head> <style type="text/css"> body {overflow: scroll; overflow-x: hidden;} .anyClass { position: relative; visibility: hidden; left: -5000px; } </style> </head> <body bgcolor="#000000"> <p><!--webbot bot="HTMLMarkup" startspan --><script language="JavaScript1.2"> <!-- /* Submitted by Marcin Wojtowicz [one_spook@hotmail.com] Featured on JavaScript Kit (http://javascriptkit.com) Modified by JK to be IE7+/ Firefox compatible For this and over 400+ free scripts, visit http://javascriptkit.com */ var trailLength = 10 // The length of trail (8 by default; put more for longer "tail") var path = "cursor_star.png" // URL of your image var standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body //create reference to common "body" across doctypes var i,d = 0 function initTrail() { // prepares the script images = new Array() // prepare the image array for (i = 0; i < parseInt(trailLength); i++) { images[i] = new Image() images[i].src = path } storage = new Array() // prepare the storage for the coordinates for (i = 0; i < images.length*3; i++) { storage[i] = 0 } for (i = 0; i < images.length; i++) { // make divs for IE and layers for Navigator document.write('<div id="obj' + i + '" style="position: absolute; z-Index: 100; height: 0; width: 0"><img src="' + images[i].src + '" width='+(16-i)+' height='+(16-i)+'></div>') } trail() } function trail() { // trailing function for (i = 0; i < images.length; i++) { // for every div/layer document.getElementById("obj" + i).style.top = storage[d]+'px' // the Y-coordinate document.getElementById("obj" + i).style.left = + storage[d+1]+'px' // the X-coordinate d = d+2 } for (i = storage.length; i >= 2; i--) { // save the coordinate for the div/layer that's behind storage[i] = storage[i-2] } d = 0 // reset for future use var timer = setTimeout("trail()",10) // call recursively } function processEvent(e) { // catches and processes the mousemove event if (window.event) { // for IE storage[0] = window.event.y+standardbody.scrollTop+10 storage[1] = window.event.x+standardbody.scrollLeft+10 } else { storage[0] = e.pageY+12 storage[1] = e.pageX+12 } } initTrail() document.onmousemove = processEvent // start capturing //--> </script><!--webbot bot="HTMLMarkup" endspan --></p> </body> I'm looking for something that allows me to add tags to a photo like this website: http://fukung.net By clicking add tag it opens a input box and once added adds to a DB. How would I do something along those lines? Where to put the <ol>&&</ol> tags so everytime i run the javascript it numbers each indivdiual items which the javascript is looping. Code: <table border="2"table align="center" cellpadding="40"> <tr> <th width="80%"> Questions & Time</th> <th>Status</th> </tr> <tr> <td><% for (int i=0; i < theList.size(); i++) {%> <tr> <td><%= theList.elementAt(i)+ " " + theTime.elementAt(i) %> <% }%> </td> <td>Where is the pending goes:</td> </tr> <tr> </table> Hi, hope someone can see an answer here. I have 4 div tags which are hidden to begin with from the css as shown below: Code: #story1 {float:left;width:100%;display:none;background:#333;color:#fff;vertical-align:top;} #story2 {float:left;width:100%;display:none;background:#333;color:#fff;vertical-align:top;} #story3 {float:left;width:100%;display:none;background:#333;color:#fff;vertical-align:bottom;} #story4 {float:left;width:100%;display:none;background:#333;color:#fff;vertical-align:bottom;} The contents of these is pulled out of a db and so the quantity of text changes (within certain parameters) and so the size of the divs changes, hence no height: setting. I know I could get around this by setting an absolute height and using overflow to show a scrollbar but I would rather not have a scrollbar as the amount of text will only be 100-200 words. Elsewhere I have used the following script to equalise div tags Code: if (document.getElementById("member1").offsetHeight < document.getElementById("member2").offsetHeight){ document.getElementById("member1").style.height = document.getElementById("member2").offsetHeight + "px"; } else { document.getElementById("member2").style.height = document.getElementById("member1").offsetHeight + "px"; } I tried this for my div tags but because they initially start with display:none it sets the height of them to zero. Is there a simple way to make all of these the same height whilst they are hidden? I'm working on a greasemonkey script that requires me to append a tag before each instance of a tag with a specific class name. It works when there's no parent tags but when it goes into levels deep it doesn't work. So how can I use insertbefore?
I forgot how to do this. I did this a long time ago but have deleted the example. I want to absolute position 11 scrolling div tags of the same dimensions with the same top and left positions. In other words, on top of each other. This is easy. What I can't remember how to do is trigger them so one shows up and the others are hidden. Code: <style> .one { position:absolute; top:200px; left:0px; background:skyblue; width:250px; height:250px; } .two { position:absolute; top:200px; left:0px; background:aqua; width:250px; height:250px; } </style> <input type="button" onClick="" value="one"> <input type="button" onClick="" value="two"> <div class="one">one</div> <div class="two">two</div> Hello there, I have one drop down list having some characters name. I have created this list dynamically using javascript. I have <h3> tag in html having same characters' name using that I had created drop down list. There are <blockquote> along with <h3> tag which is speech of that character. I have to generate the javascript in such a way that, if character "A" is selected and sppech belong to that character should be visible. Is any one help me? my following code able to match <h3> tags and hiding it but not working properly. Please help me out. Code: function selectedOption() { var indx = newSel.selectedIndex; var selectedText = newSel.options[indx].text; h3Tag = document.getElementsByTagName("h3"); var nestedH3; //alert(h3Tag); bQuote = document.getElementsByTagName("blockquote"); for(var i=0; i<h3Tag.length; i++) { tagName[i]=h3Tag[i].innerHTML; if(selectedText != tagName[i] && selectedText != "Show All Lines") { //alert("Char: "+tagName[i]); h3Tag[i].style.display = "none"; bQuote[i].style.display = "none"; } else if(selectedText == "Show All Lines") h3Tag[i].style.display = "block"; } } I'm using forum with bb rich text editor, the problem that sometimes when a user copy and paste content, there ere extra codes that are not supported like: Code: [highlight=#ff0000][/highlight] [blockquote][/blockquote] [CENTER ALIGN=CENTER][/CENTER ALIGN] Can you help me to write a script that automatically reformat the html content when pasted and only keeps specified tags like [img],[url],[b], defined in array ... If it is not possible to reformat content when paste, I can add a button to the editor and call that function to format the content and return plain text with a specific tags. I tried this script: Code: function removeHtmlTag(strx){ if(strx.indexOf("[")!=-1) { var s = strx.split("["); for(var i=0;i<s.length;i++){ if(s[i].indexOf("]")!=-1){ s[i] = s[i].substring(s[i].indexOf("]")+1,s[i].length); } } strx = s.join(""); } return strx+''; } It made to strip html tags, I replaced <> with [], It removes all tags and don't put space instead of the removed tags, example: Code: hello[h1]Name[/h1] Will be like : helloName ??? I got an idea to make a stupid trick, like converting [IMG] to {IMG} and run that function and re convert {IMG} to [IMG] ... Please help, I'm not good in Regular Expressions. Thanks for your time, Regards. I have been working on this code for days and I cannot get it right!!! Can anyone please give me any pointers. It should have an error message that pops up on same line as text boxes when into is not entered property! Thanks in advance! NewBanks <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script type="text/javascript"> function validate(){ var errorList = new Array(); var eMail = document.getElementById("email").value; var passwrd = document.getElementById("password").value; var cPassword = document.getElementById("confirmPassword").value; var secQuest = document.getElementById("securityQuestion").value; var secAns = document.getElementById("securityAnswer").value; var regEx = /^\s*[\w\\+_]+(\.[\w\\+_]+)*\@[\w\\+_]+\.[\w\\+_]+(\.[\w\\+_]+)*\s*$/; if(!regEx.test(eMail)){ errorList[errorList.length] = ("You must enter a valid email address!<br/>"); valid = false; } if(passwrd == "" || passwrd.length <6){ errorList[errorList.length] = ("Your password must be 6 characters long! <br/>"); valid = false; } if(passwrd != cPassword){ errorList[errorList.length] = ("Passwords do not match! <br/>"); valid = false; } if (secAns == ""){ errorList[errorList.length] = ("Please enter your Security Answer! <br/>"); valid = false; } if(errorList.length > 0){ for(var i = 0; i < errorList.length; i++){ document.getElementById("errors").innerHTML += errorList[i]; } return false; } else return true; window.onload = function() { 0(); } } </script> </head> <body> <form id="login" action="confirm.html"method="get" onsubmit="return validate();"/> Email: <input type="text" name="email" id="email" onblur="validate(this);" /> <br/><span id = "Invalid Email"></span> Password: <input type="text" name="password" id="password" onblur="validate(this);" /> <br/><span id = "Incorrect Password"></span> Confirm Password: <input type="text" name="password" id="confirmPassword" onblur="validate(this);" /> <br/><span id = "Invalid password"></span> Security Question: <select id = "securityQuestion" onblur="validate(this);"> <option value= "maiden" >What is your mother's maiden name </option> <option value= "animal"> What is your favorite animal </option> </select> <br/> <input type="text" name="securityAnswer" id="securityAnswer" onblur="validate(this);" /> <br/><span id = "Security Answer does not match"></span> <p><input type = "Submit" /></p> <span id = "errors"> </span> </form> </body> </html> I am trying to replace all newline characters with <br /> tags. The following two javascript functions that I've found, work in Firefox but do not work in Internet Explorer (I have version 7 installed on my machine). I would really appreciate any pointers on how to get this done. Thank you! Joe PS: I am using jQuery to call these functions. And this is how my JSP page looks like. Code: <html> <head> <title>New Line Replacement</title> <script src="/js/jquery-1.3.2.min.js" type="text/javascript"></script> <script type="text/javascript"> function replaceNewLine(myString) { var regX = /\r\n|\r|\n/g; var replaceString = '<br />'; return myString.replace(regX, replaceString); } $().ready(function(){ $(".replace-text").each(function(i) { var sBody = $(this).html(); $(this).html(replaceNewLine(sBody)); }); }); /* function nl2br(text){ text = escape(text); var re_nlchar; if(text.indexOf('%0D%0A') > -1){ re_nlchar = /%0D%0A/g ; }else if(text.indexOf('%0A') > -1){ re_nlchar = /%0A/g ; }else if(text.indexOf('%0D') > -1){ re_nlchar = /%0D/g ; } return unescape( text.replace(re_nlchar,'<br />') ); } */ </script> </head> <body> <div class="replace-text">${model.paraOne}</div> <div class="replace-text">${model.paraTwo}</div> </body> </html> |