JavaScript - Can't Access Frame Content
I'm trying to write a little Greasemonkey script (in Firefox) to manipulate the top bar Google Translate produces when translating a site. For example: http://translate.google.com/translat.../www.google.de.
Google has employed traditional HTML frames. According to many websites, I can use something like window.frames[0].contentDocument to access the first frame. However, this is refusing to work! I have been debugging this for hours. I have verified that I am indeed running the script from the top-level window (window.parent === window.top), and I am able to manipulate the frames themselves without a problem. When I try something like window.frames[0].contentDocument.URL, it returns as about:blank (I also get this with the other frame, i.e., frames[1]). I have tried several different methods of getting at that frame, including getElementsByTagName("frame")[0] (which works for manipulating the frame itself, but not for editing the frame's content through contentDocument). Here's my little script so far. I've included the first part so you can see for yourself that I'm definitely in the top-level window and using the right @include because it works. In this example, the URL returned is "about:blank" (again, I'm in Firefox). Code: // ==UserScript== // @name GTranslate // @include /^https?://translate\.google\.com/translate\?.*/ // ==/UserScript== // change how the frame is displayed var bar = document.getElementsByTagName("frame")[0]; bar.removeAttribute("noresize"); // manipulate the content inside the frame var gt = bar.contentDocument; alert(bar.URL); Similar TutorialsHi, I am new to javascript and need help to get the value from af gridview cell and write it to an asp.net control on my aspx page ( language Visual Basic ). I have a gridview ( gridview1) which contains some numbers in the first column. I need to get the number in the column on mouseover and write to an asp.net label, textbox or hiddenfield. I know how to activate the script from from my aspx page, but I havent got a clue on how to write the script. Any help is deeply appreciated. Hi. I have a question about java script code. I'm creating a website with frames. Within the main page frame, there are tables in the main content page. When I created the website, it fit perfectly in the browser window of my smaller laptop. I just checked it out on my old G5 and the images/pages are too big and either cut off or scroll bars appear (which is not what I want) So I wanted to know what code I put in my files and where to put it? Also, what pages does it need to be in? the main frame index page? the specific pages that fit within the frames? some are images that load in the frames? would i need to create an .html for those and then have the .jpg load so that it can be resized? I need the main page to be resized to fit the browser as well as the pages in the frames to fit. Can you help? Thanks I' am trying to do a frame by frame animation, lik an animated gif. I am using svg (vector graphics) and IE9 has native support for svg. The code functions in every other browser but IE9 plays the animation once then nothing. If you would like to try and not have svg files you can use whatever gif,jpg or png just put an img-tag where i have embed. Code: <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>Animation</title> <style type="text/css"> /*One div per image all uses this class*/ .eyesPos { position:absolute; width:80px; height:50px; z-index:1; left: 0px; top: 0px; } #eye_wrapper{/*This is a master div for easy placement of the others*/ position:absolute; width:80px; height:50px; z-index:2; left: 275px; top: 200px; } </style> <script> var eyes=["a","b","c","d"];//Image id in this array var startAnim=setInterval(visaOga,100);//Animation speed function visaOga(){ document.getElementById(eyes.splice(0,1)).style.display="block"; if(eyes.length==0){ document.getElementById("a").style.display="none"; document.getElementById("b").style.display="none"; document.getElementById("c").style.display="none"; dBort = function(){ document.getElementById("d").style.display="none"; eyes=["a","b","c","d"]; } setTimeout(dBort,1500);//So last image is shown 1.5 sec return;//Aborts - dBort -. Sequence can start over if(document.getElementById("d").style.display=="none"){ startAnim;//Strts sequence if last image invisible } } } </script> </head> <body> <!--Images in own div invisible at start--> <div id="eye_wrapper"> <div class="eyesPos" id="a" style= display:none;> <embed src="0.svg" width="80" height="50" /> </div> <div class="eyesPos" id="b" style= display:none;> <embed src="1.svg" width="80" height="50" /> </div> <div class="eyesPos" id="c" style= display:none;> <embed src="2.svg" width="80" height="50" /> </div> <div class="eyesPos" id="d" style= display:none;> <embed src="3.svg" width="80" height="50" /> </div> </div> </body> </html> guys help pls.. i need to pass the data in the textfields from the left frame to the textfields in the right frame of my frameset. (ex: dslnum of frame1 will be pass to txtDSLTN of frame2) frame1: http://www.mediafire.com/?hge1ws29mdhmu7e frame2: http://www.mediafire.com/?k83cb64wbpskw97 thanks in advance! I have a page called answersheet.html which I am popping up using a function called NewWindow; Code: <a href="javascript:myVoid()" onclick="NewWindow('/images/101online/practicetest1/listensubtest1/answersheet.html','PopUp','625','400','no',''); return true;"> It works fine. answersheet.html consists of two frames, the top frame containing a button with onclick="myprint()" to print out the bottom frame: Code: <script type="text/javascript"> function myprint() { window.parent.bottom.focus(); window.print(); } </script> It does the job in Internet Explorer, but Firefox and Chrome only print the top frame with the print button! Is the function myprint() IE only coding? If so, what should I use? Hi all, I am using xmlhttp.open();xmlhttp.send(); to send a php content to a div. This php content is again using the same method to get php content from a further page. The content of the div, does not seem to be using the css and javascript files defined in the calling pages <head> section. Does anyone know why this is? Is there a workaround or solution to this problem? It might be easier to understand looking at the code, so Background info: Javascript file: scripts.js client.php ----> loads data from: display_client.php display_client.php ----> loads data from: display_brand.php Code: client.php http://pastebin.com/4EFn9YRf display_client.php http://pastebin.com/BGZAKre2 display_brand.php http://pastebin.com/0a4Pg3gg scripts.js http://pastebin.com/er4dkmPc Thanks! i noticed today that if i type in my js file name in the url i get a download box, i have an htaccess on my site so this should not be happening, thats another issue.. my question is, is there a trick to creating a js file that cant be accessed in this manner, i was thinking about adding a php define statement as it comes from one source only, but i wanted to ask first to see if there was something on the js side i could do or is that strictly a htaccess or server side issue.. Hi this is what I want to do. I have an online store and a need get fixed the machines from where my clients use my web site. what I'm doing right now is using an activeX to retrieve theirs OS code, HD serial number and other stuff and is working fine but since I'm using an ActiveX they are forced to use Internet Explorer and that's the big problem. my clients agree for me doing this check on their computers, actually they allow the activex to run, but they are requesting the posibility of using for example mozilla. thanks in advance and sorry about my english I'm just learning it is said that the 'form' node can be accessed by document.forms.certainName but it fails on my browser(IE8) however for images, it works, that is, document.images.certainName returns a Node. is there bugs only on 'form' tag? btw, document.forms[0] works ... quite quirky... Sup gents. Excuse my tenaciously novice questions, but dont disparage just yet, im beginning to grasp how the mechanism behind the code words, in due part to your helpful suggestions Im in the last stages of the code. In this section i have added three methods, whose function is to direct access control over the ciphers i will be adding shortly. I firstly need for the methods to be working. What they do is, categorize the set of values inside the first array and give a set of names privileges. The three methods that deal with the access control are link(), secondgroup() and third group. Ive assigned that the first three names( link() ) can access all the ciphers, ie administrators, the next three names ( secondgroup() ) can only access the shift, permutation and vigenere ciphers and the rest ( thirdgroup() ) can access the other remaining ciphers. But ive added so much code at once that i overwhelmed myself and i now i cant figure out where ive gone wrong, be it in the syntax or the logic Code: <html> <head> <script type ="text/JavaScript"> var counter = 0; var counter2 = 0; var arraynumb = 0; var arraynumb2 = 0; var global; var array = ['Mohamad', 'Karim', 'Anthony', 'Rami', 'Natalia', 'Sarah', 'Samer', 'Violette', 'Plume', 'Sharshabil']; var array2 = ["1000", "1001", "1002", "1003", "1004", "1005", "1006", "1007", "1008", "1009"]; function pass(){ var searchKey = document.searchform.inputVal.value; for (var i = 0, len = array.length; i < len; i++){ if (array[i] == searchKey){ counter = 1; arraynumb = i; } } } function pass1(){ var searchKey2 = document.searchform.inputVal2.value; for (var i = 0, len = array2.length; i < len; i++){ if (array2[i] == searchKey2){ counter2 = 1; arraynumb2 = i; } } } function access() { if (counter == 1 && counter2 == 1 && arraynumb == arraynumb2) { window.alert("You may access the website"); global = 1; } else{ window.alert("You may not access the website"); global = 0; } } function link() { var searchKey3 = document.searchform.inputVal.value; if (global == 1 && (searchkey3 == array[0] || searchkey3 == array[1] || searchkey3 == array[2] )) { window.alert("You are an administrator, you may use all the ciphers"); } else window.alert("you are not signed in, please do so"); } function secondgroup() { var searchKey4 = document.searchform.inputVal.value; if (global == 1 && (searchkey4 == array[3] || searchkey4 == array[4] || searchkey4 == array[5] )) { window.alert("You are an ordinary user of class A, you may proceed to access the Shift, Vigenere and Permutation ciphers"); } else window.alert("You may not access this cipher"); } fucntion thirdgroup() { var searchKey5 = document.searchform.inputVal.value; if (global == 1 && (searchkey5 == array[6] || searchkey5 == array[7] || searchkey5 == array[8] || searchkey5 == array[9] )) { window.alert("You are an ordinary user of class B, you may proceed to access the Hill, Affine, Substitution and DES ciphers"); } else window.alert("You may not access this cipher"); } </script> </head> <body> <form name = "searchform" action = ""> <p>Enter username<br/> <input name = "inputVal" type = "text" size = "30"/> <input name = "search2" type = "button" value = "Search" onclick = "pass()"/> </p> <p>Enter password<br/> <input name = "inputVal2" type = "password" size = "30"/> <input name = "search" type = "button" value = "Search" onclick = "pass1()"/> <input name = "Access site" type = "button" value = "Access" onclick = "access()"/> <br/> <br/> <input name = "link to" type = "button" value = "Shift" onclick = "link();return secondgroup();" enabled=""/> <input name = "link to" type = "button" value = "Vigenere" onclick = "link();return secondgroup();" enabled=""/> <input name = "link to" type = "button" value = "Permutation" onclick = "link();return secondgroup();" enabled=""/> <input name = "link to" type = "button" value = "Hill" onclick = "link();return thirdgroup();" enabled=""/> <input name = "link to" type = "button" value = "Affine" onclick = "link();return thirdgroup();" enabled=""/> <input name = "link to" type = "button" value = "Substitution" onclick = "link();return thirdgroup();" enabled=""/> <input name = "link to" type = "button" value = "Des" onclick = "link();return thirdgroup();" enabled=""/> <br/> </p> <br/> <p></p> </form> </body> </html> hi, i want to make an ftp access page using javascript i know it's possible using "ftp://" , but when i use this, the browser loads a window with the ftp folder i want a javascript to get ftp access and to give the commands itself any1 who knows how to get ftp access and ability to give file send/receive/... commands with javascript? Hi, I am sure there is a simple thing I am doing wrong. I am using serif plus, (instead of dreamweaver), I have 12 pages, and am using 3 seperate master pages for various pages. Master page B holds the repetitive information for page7.html and contained within page7 is an iframe linked to page18.html. On page7.html, beside the iframe I have six 'hot spots' anchored within the page displayed (page18). This works really well. The problem I have is when page7.html loads it comes up at the top of the iframe, (half way down the main page), not the top of the page that contains it. I have tried putting an anchor at the top of page7.html and inserting code as in OnLoad, go to anchor etc., window.location, and just about everything else I could think of, but nothing seems to make the page open in the correct place. You have to scroll to the top each time. Can anyone help with this please. Not very experienced but hoping to learn. Sybs Here is the story... There is a submit button (POST) that targets to a frame, given that there is no way to change it through DOM manipulation. Code: <script language="JavaScript" type="text/javascript"> <!-- window.onload = function() { if (top!=window) top.location=window.location } --> </script> That piece of code is not elegant in the sense that it will show the parent window and the frame for like one second, then the content in the frame takes over to cover up the parent window. Is there a way for the frame to take over the parent window instantly? i was doing some 3d things with unity3d, and i want to embed them into web pages, or to allow others to embed it into their pages...so i managed to do it with frames. now, there is a problem when i want to open the link to my site from the application that is embedded, it opens the window but in frame, so that is just bad... embedded window is small, a bit larger then youtube default size, so it looks ugly when it opens site in it.... is there a way to pop up the window, or to open new tab from the frame? and not to involve making scripts outside the frame because it will be harder to present the user what he needs to do in order to embed this content into his page? any ideas? thank you! I have this offer iframed on my website and I want it so that when they get to a certain page (i have the specific url), I can redirect it to another site. Is this possible by any chance?
How would you access information about various attributes of an element with javascript?
Hello everybody, I am new in this forum (and I'm also new in web coding, but not in programming)... This is the first problem I met: I can't understand how to acccess a property in this snippet: Code: function FGGE() { this.totalExternals = 0; this.loadedExternals = 0; this.loadImage = function(image) { image.onload = function() { alert("Loaded 1: "+this.loadedExternals+"/"+this.totalExternals); }; alert("Loaded 2: "+this.loadedExternals+"/"+this.totalExternals); }; } Output is this: Loaded 1: NaN/undefined Loaded 2: 0/0 Could someone help me fixing "Loaded 1"? Thanks a lot Hi someone please let me know the way to access a smarty value with javascript? my smarty value is = {$value.url} i want to access it like Code: <script type="text/javascript"> function load() { document.location = '{$value.url}'; } </script> i tried with wrapping code with {literal} {/literal} but it isnt working. can some one correct this please sorry for bad english Thanks Hi, I am trying to access an XML file from a server in my JavaScript code. I have an XML file like this: -<stream version="1.2"> -<room id="simulator" time="128168557915"> -<dimention id=0 x="1.25" y="2.00"> <m mcu="160" sid="75"> </dimention> </room> -<room id="simulator" time="128168557928"> -<dimention id=0 x="1.95" y="1.86"> <m mcu="160" sid="55"> </dimention> </room> </stream> this file is generated by an application and I can access it from a URL ( since I am using the simulator for this application the XML is accessible from http://localhost:8081/feed/demo) This xml file is updated every few seconds and constantly growing. I have a javascript code which I've added the following code to it in order to use the data from XML file: <script type="text/javascript"> if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET","http://localhost:8081/feed/demo",false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; document.write("<table border='1'>"); var x=xmlDoc.getElementsByTagName("room"); for (i=0;i<x.length;i++) { document.write("<tr><td>"); document.write(xmlDoc.getElementsByTagName("dimention")[i].getAttribute("x")); document.write("</td><td>"); } document.write("</table>"); </script> Now here comes my problem: if I have the XML file saved on same drive as html page and I address it like this: xmlhttp.open("GET","floor.xml",false); it works fine, but when I pass the URL it doesn't. is there anything else I should do in case of loading the xml from URL? my second question is that I want to use the text values returned by xmlDoc.getElementsByTagName("dimention")[i].getAttribute("x") in an if statement like this : if (valuereturned = 2.00) { do sth } what is the best way to do that, since the returned value is a text. I need the answer ASAP and I really appreciate your help, thanx :-) Hello, I am trying to set up this Javascript to work with my XML exported from Microsoft Access for support on an Intranet page. I borrowed from a tutorial code but I cant seem to figure out how to get the Javascript to recognize my values in the xml file. I believe my issue is related to the formatting of the xml file. The example is formatted like Code: <index> <name><![CDATA[ Paul ]]></name> <age><![CDATA[ 26 ]]></age> <height><![CDATA[ 6'0" ]]></height> </index> While my access file exports a little messy... Sadly, unless this can be changed.. I would love to just enter the code myself for each entry.. but I need it to be exportable and immediately updated to the Javascript search. Access exports like this. Code: <Employee_x0020_Database> <Employee_x0020_Number>200786</Employee_x0020_Number> <First_x0020_Name>Stacey</First_x0020_Name> <Middle_x0020_Name>Leanne</Middle_x0020_Name> <Last_x0020_Name>Evans</Last_x0020_Name> <Gender>F</Gender> <Date_x0020_of_x0020_Hire>2005-04-07T00:00:00</Date_x0020_of_x0020_Hire> <Position>Cashier</Position> </Employee_x0020_Database> Any advice on how I can get Javascript to recognize the values without a CDdata tag? Code: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html><head><meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"> <title>Search</title> <script type="text/javascript"> window.onload = loadIndex; function loadIndex() { // load indexfile // most current browsers support document.implementation if (document.implementation && document.implementation.createDocument) { xmlDoc = document.implementation.createDocument("", "", null); xmlDoc.load("index.xml"); } // MSIE uses ActiveX else if (window.ActiveXObject) { xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async = "false"; xmlDoc.load("index.xml"); } } function searchIndex() { // search the index (duh!) if (!xmlDoc) { loadIndex(); } // get the search term from a form field with id 'searchme' var searchterm = document.getElementById("searchme").value; var allitems = xmlDoc.getElementsByTagName("item"); results = new Array; if (searchterm.length < 3) { alert("Enter at least three characters"); } else { for (var i=0;i<allitems.length;i++) { // see if the XML entry matches the search term, // and (if so) store it in an array var name = allitems[i].lastChild.nodeValue; var exp = new RegExp(searchterm,"i"); if ( name.match(exp) != null) { results.push(allitems[i]); } } // send the results to another function that displays them to the user showResults(results, searchterm); } } // Write search results to a table function showResults(results, searchterm) { if (results.length > 0) { // if there are any results, write them to a table document.write('<div><a href="search.html">New Search</a></div>You searched for <b><i>'+searchterm+'</i></b><br><br>'); document.write('<table border="1" style="width: 100%;">'); document.write('<tr><th>NAME</th><th>AGE</th><th>HEIGHT</th><th>WEIGHT</th></tr>'); for(var i=0; i<results.length; i++) { document.write('<tr>'); document.write('<td>' + results[i].getAttribute("name") + '</td>'); document.write('<td>' + results[i].getAttribute("age") + '</td>'); document.write('<td>' + results[i].getAttribute("height") + '</td>'); document.write('<td>' + results[i].getAttribute("weight") + '</td>'); document.write('</tr>'); } document.write('<table>'); document.close(); } else { // else tell the user no matches were found var notfound = alert('No results found for '+searchterm+'!'); } } </script> </head><body> <form action=""><b>Search: </b><input id="searchme" type="text" size="20"> <input value="Submit" onClick="searchIndex(); return false;" type="submit"></form> </body></html> Thanks for helping me with this... Totally way over my head on this one. Delvok |