JavaScript - Problem With Moving Scroll Bar In Iframe
I have a paragraph of text which is embedded in an IFrame. when i search particular string in that paragraph, if the string is found then the string will be highlighted and the full paragraph is loaded in IFrame. but, if the searched text is at the bottom, then scroll bar in an iframe is not automatically moved to the hidden highlighted text position. any body help me to move the scroll bar automatically to the hidden text position in the IFrame?
please run the code, type any text from the paragraph of text and click serach button. see the output. [if the searched text is at the bottom, move the scroll bar to see it in the iframe] code: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <script language="javascript" type="text/javascript"> var html = "Cascading Style Sheets (CSS) are an increasingly commmon way for website developers to control the look and feel of their web pages. A style ssheet allows the website developer to specify the size, font and color of text for an entire website without having to code the information in each page. Style sheets separate the stylle (or look and feel) of the document from the structure (or the content and ordering of information).<br/>1.This # 1 item in this loong list <br/>2.This # 2 in the list <br/>3.This # 3 item in thiis long list <br/>4.This # 4 in the list <br/>5.This # 5 item inx this long list CSS is a powerful way for content developers to preserve the desired fonts, colors, and text sizes of HTML documents. Howwever, students with disabilities can also benefit from sites designed using CSS. Individual users can choose to apply their own style sheets to documents, overriding any other style sheets. FFor example, a person with low vision could modify every CSS-enabled website to display texxt in yellow on a black background, if those colors enable her to read the text."; var iframe; var id; var doc; var index; var highlightStartTag = "<span style='color:#EE7A03'>"; var highlightEndTag = "</span>"; var wrong_word = "speltext"; var afterHighlightText; var newText; var start = 0; function highlight() { iframe = document.getElementById('frame1'); doc = iframe.document; if (iframe.contentDocument) doc = iframe.contentDocument; else if (iframe.contentWindow) doc = iframe.contentWindow.document; } function highlight1() { newText = html; var tid = document.getElementById('TextBox1'); var text = tid.value; index = newText.indexOf(text); if (index >= start) { var length = 0; length = index + wrong_word.length; var before_delim = newText.charAt(index - 1); var after_delim = newText.charAt(length); var beforeHighlightText = newText.substring(0, index - 1); afterHighlightText = newText.substring(length + 1, newText.length); newText = beforeHighlightText + before_delim + highlightStartTag + newText.substr(index, text.length) + highlightEndTag + after_delim + afterHighlightText; doc.write(newText); } else { alert("Reached End"); } return false; } </script> </head> <body onload="highlight()" > <form id="form1" runat="server"> <div> <div> <b>Sample Text:</b> <br /> Cascading Style Sheets (CSS) are an increasingly commmon way for website developers to control the look and feel of their web pages. A style ssheet allows the website developer to specify the size, font and color of text for an entire website without having to code the information in each page. Style sheets separate the stylle (or look and feel) of the document from the structure (or the content and ordering of information).<br/>1.This # 1 item in this loong list <br/>2.This # 2 in the list <br/>3.This # 3 item in thiis long list <br/>4.This # 4 in the list <br/>5.This # 5 item inx this long list CSS is a powerful way for content developers to preserve the desired fonts, colors, and text sizes of HTML documents. Howwever, students with disabilities can also benefit from sites designed using CSS. Individual users can choose to apply their own style sheets to documents, overriding any other style sheets. FFor example, a person with low vision could modify every CSS-enabled website to display texxt in yellow on a black background, if those colors enable her to read the text. </div> <br /> <b>Type the Text to Search from the above passage, for EG:"powerful"</b> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <br /> <br /> <b>Move Scroll button to see hidden highlighted text</b> <iframe id="frame1"></iframe> <br /> <br /> <asp:Button ID="Button1" runat="server" Text="Search" OnClientClick="return(highlight1());" /> </div> </form> </body> </html> Thanks, Lakshmi Similar TutorialsI am trying to find some examples of something I know I have seen in the past, but I am unable to put together a search that is coming up with anything. What I have is a div of content that I need to always be visible on the screen. The page needs to be scrolled to read through it all so I need a way for the div to move down the page as I scroll. Can anyone point me in the right direction? Hi all, I'm trying to get the cursor position to move to the end of the text within an editable iframe or div. I've been pointed to something called TextRange and have been reading up on it for days yet couldnt make sense of much (i'm still very new). what i'm trying to do is on a button click, the cursor will move to the end of the text in the iframe. any help or pointers would be greatly appreciated. thanks. Problem Solved
I have an iframe on my page which currently shows a separate website (one that i do not control). I'm trying to have the iframe automatically scroll to the bottom of the page. I'm pretty sure this is doable through javascript. The website does not have any anchor(s) or anything else that would be useful for what I'm trying to do. I've been stuck on this for over an hour now.. so please help Here is my code <iframe name="frame" id="frame" width="880px" height="600px" src="website" scrolling="no" frameborder="0"></iframe> 1) I have a webpage that contains an iframe. The iframe is scrollable. 2) I have the main body of the page responding to onmouseup clicks: <body onmouseup="hideMenus(event)"> And I have the main body of the child page (displayed in the iframe) also responding to onmouseup clicks: <body onmouseup="parent.hideMenus(event)"> So clicks on both pages result in hideMenu() on the parent page being called. Now when the scroll bars on the iframe become visible (due to large amounts of content), I click on the scroll bar, and the hideMenus() function does not respond. I guess the scroll bar is not recognized as part of either the parent page or the iframe's page. I tried adding onmouseup="hideMenus(event)" to the iframe but that didn't help. How can I get mouse clicks on the iframe's scroll bar to result in hideMenu being called? The website can be viewed he http://www.shahspace.com/bow/home.html The following script will take the option parameter from the page URL and scroll the page to the element which has the matching ID. For example: mypage.html?element3 will cause it to scroll to the element which has an id="element3" when the page loads. Code: <html><head><title></title> <script type="text/javascript"> function OptionScroll(){ if (location.search.length > 0){ LocnId=unescape(location.search.substring(1)) scrollLocn = document.getElementById(LocnId).offsetTop document.body.scrollTop = scrollLocn } } </script> </head> <body onload="OptionScroll()"> ...etc.... This works fine. Now for the next step, I want to be able to do this from a script embedded in an iframe. In other words, when the page loads, the iframe will load and a script within the iframe executes taking the parameter from the parent page's URL, and then scrolls the parent page to the element with the matching ID. Is it possible to do this? Hi, I have written a magnifier (using both CSS and JavaScript), and it appears to work OK in the four browsers I have tested (IE9, FF3.5.7, Safari 5.1, and Opera 11.51). However, Safari annoyingly puts in scroll bars when you are magnifying the picture. I can get rid of this by making the ctrlDiv offset as hidden, but then this removes the bottom scroll bar completely in all browsers (not really useful if the document is bigger than the browser window). I have read about putting the image as a background image of another element, but cannot for the life of me get this to work at all. Also, the functions to return the absolute position of elements (and mouse pointer) does not work if the document has a margin (i.e. width:1216px;margin:auto) - but I can work around this at the moment. Anyway, the complete code is at http://www.geraldholdsworth.co.uk (it was easier to stick it there and post a link than to post the code here). Cheers, Gerald. I am trying to write a function that will dynamicly add an anchor, and then scroll to it, then remove the anchor. The script is adding the anchor, and changing the hash, but no scrolling is happening, (IE7) Any idea whats wrong? Code: function set_anchor( obj ){ name = 'anchor_'+Math.floor(Math.random()*1111); new_anchor = document.createElement('A'); new_anchor.name = name; new_anchor.href = '#'+name; new_anchor.appendChild( document.createTextNode(' ') ); obj.appendChild( new_anchor ); window.location.hash = name; new_anchor.parentNode.removeChild( new_anchor ); } Hei! I am trying to use a contact form which appears in a lightbox from : http://www.xul.fr/javascript/lightbox-form.html It is working great but, of course I have a problem. My page is very big and when I want my page to scroll to the point where the form is. I am using window.scrollTo function. the problem is that before scrolling to that point , it automatically scrolls to the coordinates (0,0) and only after that. I am posting my javascript and css code. Thanks for your help ! JAVASCRIPT Code: function gradient(id, level) { var box = document.getElementById(id); box.style.opacity = level; box.style.MozOpacity = level; box.style.KhtmlOpacity = level; box.style.filter = "alpha(opacity=" + level * 100 + ")"; box.style.display="block"; if(id=='boxa') { window.scrollTo(2500,0); } else { window.scrollTo(100,100); } return; } function fadein(id) { var level = 0; while(level <= 1) { setTimeout( "gradient('" + id + "'," + level + ")", (level* 1000) + 10); level += 0.01; } } function openbox(formtitle, fadin,boxtitle,boxN) { var box = document.getElementById(boxN); document.getElementById('filter').style.display='block'; //var btitle = document.getElementById(boxtitle); // btitle.innerHTML = formtitle; // var btitle = document.getElementById(boxtitle); // btitle.innerHTML = formtitle; if(fadin) { gradient(boxN, 0); fadein(boxN); } else { box.style.display='block'; } } // Close the lightbox function closebox() { document.getElementById('box').style.display='none'; document.getElementById('filter').style.display='none'; document.getElementById('boxa').style.display='none'; document.getElementById('filter').style.display='none'; } CSS Code: #filter { display: none; position: absolute; top: -500px; left: -500px; width: 7200px; height: 3300px; background-color: #000; z-index:10; opacity:0.5; filter: alpha(opacity=50); } #box { display: none; position: absolute; top: 20%; left: 20%; width: 400px; height: 200px; padding: 48px; margin:0; border: 1px solid black; background-color: white; z-index:101; overflow: none; } #boxtitle { position:absolute; float:center; top:0; left:0; width:496px; height:24px; padding:0; padding-top:4px; left-padding:8px; margin:0; border-bottom:4px solid #3CF; background-color: #09c; color:white; text-align:center; } #boxa { display: none; position: absolute; top: 350px; left: 2950px; width: 700px; height: 200px; padding: 48px; z-index:101; overflow: visible; /* background-image: url(../imagini/tutorial.png); */ background-repeat:no-repeat; } Been tinkering with X7Chat, a php/javascript chat app, and have run into a problem putting it in an iframe. Works fine in a full or popup window, but one of the functions hangs when the app is run in an iframe or frameset. I know iframes can be picky about relative/absolute urls, but this one has me stumped. Too much code to post, but here's the error: Line: 140 Char: 3 Error: 'opener.window.parent.frames.profile.document' is null or not an object Code: 0 URL: http://www.xxxxxxxx.org/x7chat/index...General%20Chat Not sure, but I believe the problem involves this function: Code: $script = " <script language=\"javascript\" type=\"text/javascript\">\n opener.window.clearTheWay(); opener.window.parent.frames['profile'].document.location='./index.php?act=frame&frame=profile&room=$_GET[room]&user=$_GET[user]&tto=1';\n </script>\n "; The X7Chat website appears to be abandoned - support forum is offline, and emails are returned. Any bright ideas would be appreciated. Hi, I am building a chat/messenger application using PHP and Javascript. I currently have two iframes, one has the chat, the other the users in the database and their status, which is set to default 'offline' and updated to 'online' when logging in.There is also an option to change colour of both iframes like so: [CODE]function change_background_pink() { document.frames.chatContents.document.body.style.backgroundColor="pink"; [CODE] and then this code to call the function: [CODE]<BUTTON onclick=change_background_pink()>Pink</BUTTON>[CODE] The problem is, that when the frames refresh, the background of the users frame goes back to the default white colour (the text does change to show newly logged users), yet the chat one stays the newly selected colour as intended (again the text changes as required). Here is the code of the iframe as it stands now: [CODE] <?php include("connect.php"); $query=mysql_query("SELECT * FROM users;"); echo "<table style='font-family:arial;font-size:14px;'>"; // echo "<th align=left>Username:" . "<th align=left>Status:"; //while loop for rows while($rows=mysql_fetch_array($query)){ echo "<tr>"; //show member deatils echo "<td>" . $rows['username'] . "</td>" . "<td>" . $rows['status'] . "</td>"; echo "</tr>"; } ?> <script type="text/javascript"><!-- setTimeout("refreshiframe()", 10000); //poll server in one second function refreshiframe(){ document.location.reload(); } //--> </script> [CODE] What I am asking is if anybody knows how i can just refresh the actual text part of the frame from the database rather than the entire frame? Many, many thanks in advance for any advice i may recieve and sorry if it sounds confusing i cannot think of a simpler way of explaining it. Hello, i'm trying to post news on my site. so i was able to reached this http://www.shmtestforums.uphero.com/...ller/test.html but i couldn't get, exactly what i want. i really want is when load the page it should shows only 3 rows then after few seconds(say 2 seconds), the 1st row should disappear and bellow 3 rows should come up (eg. when google_1 row is disappear, google_2 & google_3 & google_4 rows should come up) this rotation should be continuous i tried this many. but no positive result. so please.... please....help me to solve this. this is the problematic java script, Code: <script type="text/javascript"> var scrollspeed=cache=1 var initialdelay=500 function initializeScroller(){ dataobj=document.all? document.all.datacontainer : document.getElementById("datacontainer") dataobj.style.top="5px" setTimeout("getdataheight()", initialdelay) } function getdataheight(){ thelength=dataobj.offsetHeight if (thelength==0) setTimeout("getdataheight()",10) else scrollDiv() } function scrollDiv(){ dataobj.style.top=parseInt(dataobj.style.top)-scrollspeed+"px" if (parseInt(dataobj.style.top)<thelength*(-1)) dataobj.style.top="5px" setTimeout("scrollDiv()",40) } if (window.addEventListener) window.addEventListener("load", initializeScroller, false) else if (window.attachEvent) window.attachEvent("onload", initializeScroller) else window.onload=initializeScroller </script> thank you . I'm using a simple PHP login script (this one: http://www.zubrag.com/scripts/password-protect.php) in tandem with Fancybox (he http://fancybox.net/). The Fancybox pop-ups on my pages use iframes, to hold written content and links. When I log in once, I can access all the regular HTML pages inside the login script without having to log in again. But when I click Fancybox's pop-up links, the pop-up is logged OUT. How can I make all the iframe pop-ups stay logged in when the user is logged in? Thanks for any help, much appreciated. Ok, I have a problem with iframe code my function looks like this: Code: createPlayer: function (cfg) { var div = document.getElementById(cfg.block2); var hold = document.createElement('div'); hold.className = 'ytPlayer'; var iframe = document.createElement('iframe'); iframe.setAttribute('id', cfg.block + 'Player'); iframe.setAttribute('width', '70%'); iframe.setAttribute('height', cfg.height); iframe.setAttribute('frameBorder', '0'); iframe.setAttribute('src', 'http://www.youtube.com/embed/' + ytPlayerParams.videoId + '?enablejsapi=1&autoplay=' + ytPlayerParams.autoplay + '&modestbranding=1');//controlbar set iframe.setAttribute('allowfullscreen', ''); hold.appendChild(iframe); div.insertBefore(hold, div.firstChild); //return iframe; }, and i was trying to add something that will call a function when the video in iframe will end.. i tryed setting evets for onStateChange but didnt work (probably did something wrong).. i tryed alot of things but it just didnt work when i paused the vid or when vid ended.. can anyone somehow help me?? Thanks in advance. Code: window.onload = function() { var vIframeUrl; vIframeUrl= document.getElementById("ifrBDiagram").src; if (vIframeUrl == "#" && document.getElementById("txtBnr").value == "") { document.getElementById("ifrBDiagram").src = "C://eBondingDiagram//Infineon.jpg"; } getIframeSize(); } function getIframeSize() { //Get window width and height var winW = 630, winH = 460; if (document.body && document.body.offsetWidth) { winW = document.body.offsetWidth; winH = document.body.offsetHeight; } if (document.compatMode=='CSS1Compat' && document.documentElement && document.documentElement.offsetWidth ) {//alert("in 2"); winW = document.documentElement.offsetWidth; winH = document.documentElement.offsetHeight; } if (window.innerWidth && window.innerHeight) {//alert("in 3"); winW = window.innerWidth; winH = window.innerHeight; } document.getElementById("ifrBDiagram").width = (winW * 0.95); document.getElementById("ifrBDiagram").height = (winH * 0.88); } Code: <table width="100%" height="100%" bgcolor="#CAD4E3" align="center" valign="center" style="border: 5px solid;"> <tr> <td><b>Bnr No:</b></td> <td><input type="text" id="txtBnr" name="txtBnr" /></td> <td> </td> <td> </td> </tr> <tr> <td><b>Lot No:</b></td> <td><input type="text" id="txtLot" name="txtLot" /></td> <td><INPUT id="btnCopy" TYPE="button" VALUE="Bonding Diagram" ONCLICK="fncCopy()"> <INPUT id="btnUpdate" TYPE="button" VALUE="End Lot" ONCLICK="reloadPage()"></td> <td> </td> </tr> <tr> <td><b>Failure Catalogues:</b></td> <td><select id="myList"> <option></option> <option>DSO</option> <option>Pre-Assembly</option> <option>PO EOL</option> <option>TDSON/TSDSON</option> <option>S308/WISON</option> </select> </td> <td><INPUT id="btnCata" TYPE="button" VALUE="Failure Catalogue" ONCLICK="fcnFailureCatalogue()"></td> <td> </td> </tr> <tr> <td colspan="4"> <iframe name="ifrBDiagram" id="ifrBDiagram" src=# style="border-width:4px; border-style:solid; border-color:blue;"> <span id="sMsg"></span> </iframe> </td> </tr> </table> When I first run the html , the interface just goes like this. After I press F5 to refresh the window, it displays this. The image just wont fit the iframe exactly. Can anyone please help to spot the bug ? I tried to use different resolution picture but still, the problem just doesn't solve. Is it really because of the image resolution ? Or something else gone wrong in my html ? Thanks Hi all let me start off by saying: "AAAAAAHHHHHHHAAAAAAA" Feel better now! I have an iFrame which loads individual pages from my site, I am using javaScript to tell the iFrame to resize to the size of the page that is being loaded, the problem is when I click on the link the iFrame does not resize but if I click on the link again it does resize! The fuction is called but only the second time round. Also the none of the script works in FireFox! HELP PLZ! My Code: Code: <SCRIPT LANGUAGE=javascript> <!-- function reSize() { try{ var oBody = ifrm.document.body; var oFrame = document.all("ifrm"); oFrame.style.height = oBody.scrollHeight + (oBody.offsetHeight - oBody.clientHeight); } //An error is raised if the IFrame domain != its container's domain catch(e) { window.status = 'Error: ' + e.number + '; ' + e.description; } } //--> </SCRIPT> <body onload="reSize()" onresize="reSize()"> <li> <a href="home.html" rel="nofollow" target="info" onclick="reSize();"> <img src="css/images/home.gif" width="40" height="40" alt="" class="nav_menu_image" /> <span class="nav_title">Home</span> <br/> </a> </li> <iframe onresize=reSize() id=ifrm src="home.html" name="info" frameborder="0" padding="0" vspace="0" hspace="0" marginwidth="0" marginheight="0" width="500px" allowTransparency="true" noresize> </iframe> Hi there everybody, I've got this problem which I can't solve myself... I've got a website which has 3 colums and is hosted on domain1.com. in the right column I've got an Iframe which loads content from domain2.com . this content are some textboxes and a datepicker tool. if I press the 'search'-button in this Iframe I would like to refresh the mainpage (from domain1.com) so that another Iframe appears in the middle column. in this column i would like to load a new form from domain2.com which contains the values that I've put in in the form from the right Iframe. Unfortunally I can't get this to work... Will somebody please help me? Hi all, I hope you can help I have some code which: 1) Opens a URL (e.g. google.com) in a hidden iframe, then 2) Redirects the visitor to a different URL (e.g. yahoo.com) after it has loaded... This works exactly as I need. What I'd like to do is the following: 1) Open a URL (e.g. google.com) in a hidden iframe, then 2) Redirect the visitor to a different URL (e.g. yahoo.com) in a full-screen iframe 3) The address bar of the full-screen iframe should be my domain (obviously!) Here's what I have so far... Hidden iframe -> New URL Code: Code: <html> <body> <script type="text/javascript"> var page_body = document.getElementsByTagName('body'); var myframe = document.createElement('iframe'); var id = Math.random(); myframe.setAttribute('id', 'myFrame'+id); myframe.src = 'http://google.com'; //First open Google in hidden iframe myframe.setAttribute('frameborder', '0') myframe.setAttribute('width', '0'); myframe.setAttribute('height', '0'); if (myframe.attachEvent) { myframe.attachEvent('onload', function() { top.location = 'http://yahoo.com'; //Once loaded redirect to Yahoo -- but the address bar shows yahoo.com -- I want the address bar to display mydomain.com/page.html }); } else if (myframe.addEventListener) { myframe.addEventListener('load', function() { top.location = ('http://yahoo.com'); }, false); } page_body[0].appendChild(myframe); </script> </body> </html> I have an example of some code which displays the full screen iframe, but my problem is... ...I can't figure out how to redirect to this after the hidden iframe has loaded Here's an example of how I want the redirect to display -- after the initial hidden iframe has loaded: Code: <html> <head> <script type="text/javascript"> function sendParams() { document.body.style.overflow = "hidden"; } </script> </head> <body> <!--Open Yahoo.com in a full screen iframe, and disable extra scrollbar --> <iframe height="100%" width="100%" frameBorder="no" onload="sendParams()" src="http://yahoo.com"></iframe> </body> </html> I've been beating my head against the wall today trying to figure this out, and I'm fresh out of ideas. If you can help, you'll have some serious gratitude and good karma thrown your way! Best wishes, and thanks in advance, Paul |