JavaScript - Targeting Iframe
Hello, I've been spending sometime on this project now I had a few PHP problem but have got them resolved. The one problem that I'm currently having is setting the target for a image upload form to send the data to another page so that the page never actually refreshes. I got this working just fine on Google Chrome, Firefox and so on but in internet explorer this is still a problem. Whenever you click submit to start the uploading of the picture it pops up a new window to the upload.php page that PHP script runs on. Its not suppose to do that, it is just suppose to run in the background and upload normally without any window popping up. I don't understand why it is doing this, I've seen other scripts do the same thing that I'm doing here but mine for some reason mine isn't working correctly in internet explorer. Maybe you guys can give me idea to what is wrong with this.
Code: function showPhotoUpload() { //Apply the the black transparent background var overlay = document.createElement("div"); overlay.setAttribute("id","overlay"); overlay.style.cssText="z-index:3; background:#111111; min-width:100%; min-height:100%; max-height:120%; max-width:120%; position:absolute; top:0; opacity:0.5; filter:alpha(opacity:50);"; document.body.appendChild(overlay).lastChild; //Append the photo container var photoContainer = document.createElement("div"); photoContainer.style.cssText="z-index:4; background:#f1f1f1; width:400px; height:240px; overflow:hidden; position:absolute; top:20%; left:35%;"; photoContainer.setAttribute("id","photoContainer"); photoContainer.innerHTML = "<div id=\"photo-opt\">Please select a image file from your computer: <a href=\"javascript:;\" onclick=\"closePhotoUpload();\">Close</a><div id=\"file-upload\"><form method=\"post\" id=\"photo-upload\" action=\"upload.php\" enctype=\"multipart/form-data\"><input name=\"photo\" type=\"file\" /><input name=\"submit\" type=\"submit\" value=\"Upload\" /></form></div><div id=\"loading\"></div></div"; document.body.appendChild(photoContainer).lastChild; pushData(); } function createIframe() { var iframe = document.createElement("iframe"); iframe.setAttribute("width","0"); iframe.setAttribute("height","0"); iframe.setAttribute("name","upload_target"); iframe.setAttribute("src",""); iframe.setAttribute("style","width:0px; height:0px; border:0;"); iframe.setAttribute("id","upload_target"); document.body.appendChild(iframe); } function pushData() { document.getElementById('photo-upload').onsubmit=function() { createIframe(); document.forms[1].target = 'upload_target'; //'upload_target' is the name of the iframe setTimeout("document.body.removeChild(document.getElementById('upload_target'))", 250); } } function closePhotoUpload() { var photoContainer = _('photoContainer'); var overlay = _('overlay'); document.body.removeChild(photoContainer); document.body.removeChild(overlay); } The ones that need to be focused on the most is the createIframe() and pushData(). Those are the two that are suppose to do the magic. The pushData() function gets called in the showPhotoUpload() function. Thanks for the help. Similar TutorialsCan someone teel me what I need to do to target the links to frames? <!doctype html public "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Tree View</title> <link rel="stylesheet" type="text/css" href="css/multi/tree.css"> <script type="text/javascript" src="build/yahoo.js" ></script> <script type="text/javascript" src="build/event.js"></script> <script type="text/javascript" src="build/treeview.js" ></script> <script type="text/javascript" src="build/jktreeview.js" ></script> <!-- Below is Style sheet for demos. Removed if desired --> <style type="text/css"> body {font: normal 11px verdana, sans-serif; color: #333; line-height: 19px;} a { text-decoration: underline; color: #46546C; } a:hover { text-decoration: underline; color: #4d77c3; } #tree1 {width:250px;padding: 10px;float:left;} #tree2 {width:250px;padding: 10px;float:left;} #tree3 {width:250px;padding: 10px;float:left;} </style> </head> <body> <h2>Folding TreeView Menu demo: <a href="http://www.javascriptkit.com/script/treeview/">More info</a></h2> <!--Empty DIV tags to contain the treeview demos --> <div id="tree1"></div> <div id="tree2"></div> <div id="tree3" class="treemenu"></div> <script type="text/javascript"> var palmtree=new jktreeview("tree3") palmtree.addItem("Coding Forums", "", "http://www.codingforums.com") palmtree.addItem("PHP Reference", "", "http://www.php.net") palmtree.addItem("Mozilla Dev Center", "", "http://developer.mozilla.org/en/docs/Main_Page") var branch4=palmtree.addItem("CSS Drive") //A TREE BRANCH WITH NO URL FOR ITSELF palmtree.addItem("CSS Gallery", branch4, "http://www.cssdrive.com") //Add this item to branch4 palmtree.addItem("Web Design News", branch4, "http://www.cssdrive.com/index.php/news/") //Add this item to branch3 palmtree.addItem("CSS Compressor", branch4, "http://www.cssdrive.com/index.php/main/csscompressor/") //Add this item to branch3 palmtree.addItem("Ajaxian", "", "http://ajaxian.com/") palmtree.treetop.draw(); //REQUIRED LINE: Initalize tree </script> </body> </html> Hi, I have 2 groups of ads, 6 banners with different languages in each group. The only difference between those groups is the color. All 12 banners has the same size. I want to know how can I do Geo Targeting for those two groups. And how can I seperate each group with a tracking link that will tell me which color converts better. Will appreciate also a good resourse to learn from - website, tutorial, guide... Many thanks. This seems like it would be so simple and I have absolutely no idea. I have one page with no frames, and two links on it. The second page has an iframe on it. Both links on page 1 point to page 2 (which houses the iframe), but based on which link is clicked will determine what that iframe will display. Basically I need to figure out a way to target the iframe on page 2 after executing a window.open statement. Much like how google images creates a frame at the top after you click on one of the images from the search results. I've attached two simple files to better explain what I'm trying to do. FrameSet.zip I'd appreciate the help, I'm losing my mind. Hi all Ive basically 3 php scripts: -one that writes an xml file from a directory of image files -one that creates a thumbnail from a jpeg file resizes it and puts a little drop shadow on the thumbnail -one that reads the xml file and outputs the html code so all is good a little old school, but it works, I get a page of thumbnails in whatever form I want with links. Ive attached a lightbox script I found to open the thumbnails and thats ok. What I would like to do is target the images to a container inside a div tag using jquery, maybe even fade the image in something fancy. but Id be happy with the basics. Just click on the thumbnail show it in the adjacent container. (dont have a container yet thats what i need some help with with) I'm doing my best going through various tutorials and the chm file learning as I go here is the test page that outputs the thumbnails: http://www.eagleview.ca/newsite/cont...om=0&pageto=12 any help is appreciated william Hi Guys i wonder if any one would be able to do this, i know its a hard one! Im wanting to use the following site but rather than copy pasting links (like they ask you to) i would rather use a script to grab the link and echo it for me. The reason being i think embedding they channels the offer would be far easier. So heres the challenge: The target is the stream url at the bottom of this page: http://www.zapni.tv/play.php?id=100 (looks like this Code: http://www.zapni.tv/stream/vlc.php?id=100&session=NTEzNjcwMzY2OQ==&stream=play ) the aim is to be able to write it into a player on page load like this: Code: <embed type="application/x-vlc-plugin" name="VLC" autoplay="yes" loop="no" volume="100" width="640" height="480" target="http://www.zapni.tv/stream/vlc.php?id=100&session=MTk3NjYwODUzOQ==&stream=play"> Cheers Guys in advance, and good luck! BTW i only hope Javascript is the correct category if not, sorry :-) Hello I would like some help. The ebay editor kit produces code that is in javascript format. Is it possible to edit that javascript so it is IP geo targeted. Meaning that the javascript will show ads from the ebay site of the visitors country? I was reading the Ebay Partners Network blog and it stated it can be done using third party scripts and geoip database. If this can be done by php then any advice would be very greatfull. Thanks all in advance. Is there a way to resize an iframe dynamically so that you never get the scroll bar and essentially hide that there is an iframe? Better integration really. Basically I want to iframe a forum into my site so that the design down the sides and top which my friend does using iweb are not messed with. We have a central area which can be longer or shorter depending on the forum. 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 I have used iframes for my site and found various javascripts so when a person clicks on say the audio page he http://www.krillmeed.com/index.html it takes them to the audio page but will load it into the index.html page. The problem is, especially with search engines, to point to that page, this is what the URL looks like to send someone to that page: http://www.krillmeed.com/?frame=0&sr...m%2Faudio.html which is not very clean at all, this is the javascript that i found that at least works: Child iframe script: Code: <script type="text/javascript"> (function(){ var qstr = '?frame=0&src=' + encodeURIComponent(location.href), lre = new RegExp('^' + location.protocol + '//' + location.hostname + '(()|(/)|(/index.html)|(/index.php))(()|(\\' + qstr + '))$'); if (!lre.test(parent.location.href)){ top.location.href = '/' + qstr; } })(); </script> Parent iframe Script: Code: <script type="text/javascript"> (function(){ function getQval(n) { if(typeof n !== 'string'){ return null; } var r = new RegExp('[?&;]' + n + '=([^&;#]*)'), m = location.search; return (m = r.exec(m))? unescape(m[1]) : null; } var f = getQval('frame'), s = getQval('src'); if(f && frames[f] && s && s.indexOf(location.protocol + '//' + location.hostname + '/') === 0){ frames[f].location.href = s; } })(); </script> Is there a "cleaner" way of doing this? This was an old code, i have yet to find a more modern one. Thank you in advance. Hi, Not sure if I worded that question right. I have a web page which will display another web page in an iframe. But the content inside the iframe may change while the user interacts with it so I need to be able to resize the iframe height from code on the page inside the iframe. Any tips on how I can do that? I am using php and javascript. Thanks. I have an iframe that is a specific height and width. I want to detect whenever the the iframe is no longer exactly the height i set it to. If a user has CSS turned off for example the iframe will be in default height and width. I want to detect that. This is how you'd normally do it but this only returns the original size (try with 'no style' in Firefox): Code: function getSize() { alert('height is now '+document.getElementById("Iframemain").height) alert('height is now '+document.getElementById("Iframemain").width) } Is it possible? Hello to all and thanks in advance for my help. I know this has been posted in different places on the web but I have found no solid solution. Here is my problem: I have an iframe the loads up a page on a remote server (out of my hands) and when I send certain information to it, the page redirects my entire site to their 404 page. I need to prevent this from happening so I engaged in much research and found this... temporary fix: Code: <script> // No redirection! var prevent_bust = 0 window.onbeforeunload = function() { prevent_bust++ } setInterval(function() { if (prevent_bust > 0) { prevent_bust -= 2 window.top.location = 'http://www.mysite.com/my404.html' } }, 1) </script> What this code does, is that every time the unload of a page happens, it will redirect me to my404.html and this does solve the problem of the iframe trying to redirect my entire site but anytime a user tried to go to a new website by typing it in the address bar, they are redirected to my404.html. Is there another solution for me so that the page within the iframe cannot redirect the parent page? Hi I have a page with 3 iFrames, showing different content. iFrame1: Here is a navigation php page. Click on a menu item and it loads a php page in iFrame2 iFrame2: Here is a list of items from a database. iFrame3: I load 3 different php pages here. (A) is the main showing page. (B) and (C) is a record manipulation page, that does some editing in the database and then redirects to (A). When the (A) php page loads, it should reload iFrame2 I have tried to put something like: <body onLoad=parent.location.reload()> and put it on the (A) php page. This will reload the entire page, which works. However, it results in a loop of reloads, as the (A) iFrame file will load with the entire page reload... So, I was looking for the right code to put, like onLoad=iFrame2.location.reload() However, I can't seem to find the correct code, so I hope any of you can help me... Hello.... I've 2 iframes. And i want to change the css class of second iframe anchor tag from the first. Code: <div id="top-navigation" title="top-navi"> <ul><li id="homePageLink" class="first"> <a id="homePageTab" class="navigation-font" href="</a> </li> </ul> </div> In the above code how can i change the class="navigation-font" from the first iframe? Please help.... Hi Am new to javascript. I have a requirement where user clicks on a image which should direct to iframe. Please follow 2 scripts and please advice how to open iframe link instead of link in window.open Image code: <img src = "../samples/images/Edit3.png" alt = "Edit Status" height = 13 width = 13 onclick = "window.open('../cgi-bin/cognos.cgi?b_action=cognosViewer&ui.action=run&ui.object=%2fcontent%2ffolder%5b%40name%3d%27NARM%27% 5d%2fpackage%5b%40name%3d%27TM1_NARM_RISK_DASHBOARD_CREDIT_FINANCE%27%5d%2ffolder%5b%40name%3d%27Cre dit%20Finance%20Overlay%20Reports%27%5d%2freport%5b%40name%3d%27%23%2060%2b%20Rate%27%5d&ui.name=%23 %2060%2b%20Rate&run.outputFormat=&run.prompt=true','KPIDetail','width=600,height=350,scrollbars=yes,left=300,top=300')"> Iframe code: <iframe src="http://tm1lab.us.hsbc/TM1Web/TM1WebMain.aspx?AdminHost=tm1lab.us.hsbc&TM1Server=narm_risk_dashboard&action=OpenObject&type=Webshe et&value=Applications/CF_Commentary/H60Rate" width="100%" height = "100%" scrolling=no > </iframe> Hello, I've lately brought a new search engine scirpt however I was wonder how i could grap what ever the url is being viewed in the iframe, in order to create a hyperlink button which wil take the user to what ever is displayed in the iframe, but without my frame? Very simplilar to the 'remove frame' link that google images has on it's search result pages. I firstly thought that a PHP code would have being able to do this. However after being told my a number of PHP experts I relised that Java was the way forward. Therefore I would love any help what so ever in help me to carry out this task. I've attached the search page from my site with the iframe located. However i've had to change the file from PHP to txt. Many Thanks Hello Experts I need your advice. I dont know if this is the write place to post my query. But I have an assignment due today. I have got everything working except an iframe that is driving me nuts. the question on the assignment asks to insert a command to write the HTML code <iframe src='weekday.htm'></iframe> to the webpage where weekday is the text string returned by the weekDay() function. The iframe should display the daily schedules that are stored in the sunday.htm through saturday.htm file. The weekDay() function is located in an external .js file that I have already linked to my webpage. Another thing is there is no weekday.htm file instead there are files sunday.htm through saturday.htm that have the daily schedules to de displayed in the iframe. I know that I should some link the weekday.htm file to the weekDay() function. This is what I have done so far: <h2 id="title">Today at the Union</h2> <p> <script type="text/javascript"> /* Dispaly the daily schedule in an inline frame. Display schedules are stored in the files sunday.htm through saturday.htm */ <iframe src='weekday.htm'> var weekday = weekDay(); document.write(weekday); </iframe> </script> </p> Please advice as to how to get this thing working. I am not an expert( I am still learning.) I tried my best (spent several hours breaking my head on this). So any help is much appreciated. Thank you for your time Above is the image of my situation, what I need is for the captcha's to be loaded perfectly and displayed to the user as shown in the image with the green box around it, I currently have a script to set focus to the text field however it is kind of messy for some reason and ends up leaving it looking like the frame in the red box in the image. Here is what I have been using: Code: if (( document.URL.indexOf("cast_skills") != -1 ) || ( document.URL.indexOf("security_prompt") != -1 ) || ( document.URL.indexOf("joinraid") != -1 )){ if ( document.forms.length > 0 ) { document.forms[0].elements[1].focus(); } } This works fine since on each of the pages it is required there is only 1 form. However when loading smaller frames it causes some problem. The next question I have to ask is, is it possible to have a script that when the enter key is pressed inside frame 1, automatically move the focus on to the text field in frame 2? Noting that the page inside the frames is not my own and I cannot do anything with it. Any help would be appreciated with this matter, Many thanks. does not work in iframe, the error described he http://groups.google.com/group/ie7-j...73a3e?lnk=raot if I do correction as suggested then the error dissapears, but does not work (hover). Anyone found solution for that ? |