JavaScript - Open A Link In A External Iframe
I have two pages A and B.
I have a link in the page A. I have two iframes in the page B. In practice, the link in the page A must open the page B and the link's href must open in the second iframe of the page B. Is there any script that does this? Similar TutorialsHello folks! I don't know anything about JavaScript but I found a really cool snippet I use a lot. It will randomize images and each image can open a new link. It looks like this: ---------------------------------------------------- <script language="JavaScript" type="text/javascript"> function random_imglink(){ var myimages=new Array() myimages[1]="/img/images1.jpg" myimages[2]="/img/images2.jpg" myimages[3]="/img/images3.jpg" var imagelinks=new Array() imagelinks[1]="http://www.google.com" imagelinks[2]="http://www.yahoo.com" imagelinks[3]="http://www.alexa.com" var ry=Math.floor(Math.random()*myimages.length) if (ry==0) ry=1 document.write('<a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" border=0></a>') } random_imglink() //--> </script> ------------------------------------------------- Now, my question is, can I link to open a document within an iFrame on my page? Please don't tell me not to use iframes or whatever, I'm not a professional, just want to see if this works. Hi everyone, I'm a newbie and this is probably really easy but it just won't work! I've tried looking at various online sources but they are all either too technical or don't seem to work. I'm obviously doing something wrong! The code is posted below, it's not very long so hopefully someone will be able to debug it! Thanks lots! Original page: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>variables</title> </head> <body> <script src="displaydate.js" type="text/javascript"></script> <br> </body> </html> External displaydate.js file: Code: function todaydate(){ var today_date= new Date() var myyear=today_date.getYear() var mymonth=today_date.getMonth()+1 var mytoday=today_date.getDate() document.write(myyear+"/"+mymonth+"/"+mytoday) } Opening the original page in my browser displays nothing. Just a blank page. Any help you can give would be greatly appreciated! Geoff I need help turning the following inline code: Code: <a href="http://www.bing.com/" name="bing" onclick="return !window.open(this.href)">Bing</a><br> <a href="http://www.lycos.com/" name="lycos" onclick="return !window.open(this.href)">Lycos</a><br> <a href="http://www.dogpile.com/" name="dogpile" onclick="return !window.open(this.href)">DogPile</a><br> into an external javascript function that will do the same thing (open all links in a new window individually if javascript is enabled, without destroying links in html for if javascript is not enabled). Any smarties out there have any good suggestions? Disclaimer 1: I am not a programmer, just a curious designer, so please take that into consideration in your replies. Disclaimer 2: Despite all advices against it, I couldn't find a better solution to my website than using iFrame Disclaimer 3: Before asking for help, I researched *several* forums and although I found people discussing similar issues, I was not successful at adapting their solutions to my needs. Gentlemen, I need your help implementing a method to intercept and redirect external links to a dynamic iframe. By "dynamic" iframe I mean an iframe whose SRC would be filled up in accordance to the external URL being intercepted and that it would resize its HEIGHT accordingly in order to avoid scroll bars. The function for resizing the iframe id="child" is already correctly implemented like so: Code: <script language="JavaScript"> <!-- function calcHeight() { //find the height of the internal page var the_height= document.getElementById('child').contentWindow. document.body.scrollHeight; //change the height of the iframe document.getElementById('child').height= the_height; } //--> </script> and the call Code: <iframe src="/main/index.php" width="100%" onLoad="calcHeight();" height="1" marginheight="0" marginwidth="0" scrolling="no" frameborder="0" id="child"> This what I have going on: - index.html => contains some content and the iframe id="child" - childpage1[...N].php => several PHP pages which I do not want to show up outside of the parent "index.html". These pages use clean URLs from CMS such as "http://mydomain.com/pages/this-is-a-child-page/" Users might click on external links from search engines, for instance, about an specific page such as "http://mydomain.com/pages/this-is-child-page-7/" which obviously would load the page "orphaned", outside "index.html" and that is exactly what I am trying to avoid. Based on what I have researched so far, the best way (please, correct me if I'm wrong) to deal with this would be implementing a test condition on the header of the PHP child pages to verify if they are on "top" or not (if they are already inside the "parent" object "index.html"). If FALSE, the page would load normally, if TRUE, a variable should be created to store the URL of the requested page and passed through the link to the page "index.html" which would be immediately called. In "index.html" there would be a script to collect the variable sent through the link (something like "http://mydomain.com/?var=http://mydomain.com/pages/this-is-child-page-7/") and break the text string apart, store a portion of PATHNAME (in this case, "/pages/this-is-child-page-7/) and use it to replace the current SRC of iframe id="child". Probably, there would have to be another testing function in this script to compare the variable passed from the "orphaned" PHP page against the current value of SRC in iframe id="child" to determine if any action is actually required. This "replacement" function would be called onLoad and if tested true would run and refresh the page with the proper value in the iframe SRC. All this should be accomplished while still making the iframe HEIGHT dynamically adjustable and show a "clean" URL in the browser, such as "http://mydomain.com". The potential issues I foresee is an infinite loop due to two onLoad queries (one for SRC, another for HEIGHT) in the parent and child objects, which might required a merge into a single script. As you can tell, I have an idea of what needs to be done but not a clue on how to get it done. Any help would be greatly appreciated. Thanks, Hello. I have built a basic website that contains an iframe in the middle, called "iframe1". In this iframe I wish to load an external message board from proboards.com. In my code I can easily do this by making a button or hyper-link with the href="httproboards.com/myforums" and the rel="nofollow" target="iframe1" When I do this it will load inside of it the iframe jsut as I want it to. However, my the problem is when you click on the button to login its coded to target "_top" and it opens on the entire page replacing the whole website. If i run firebug (a real time HTML editor). I can easily locate and change the link code to rel="nofollow" target="iframe1". But How can I write a script in javascript in my webpage code to do this as soon as the iframe has loaded the external messageboard? I have also been trying things like javascript:void(document.iframe1.getElementsByTag("a")[5].rel="nofollow" target="iframe1") but i have had no luck so far in changing the target without the aid of firebug. Here is the code that needs to be changed. the rel="nofollow" target="_top" needs to be altered somehow to rel="nofollow" target="iframe1" as soon as the frame has finished loading the messageboards. Code: <p><font size="2"> Welcome Guest. Please <a href="/index.cgi?action=login" rel="nofollow" target="_top">Login</a> or <a href="/index.cgi?action=register" rel="nofollow" target="_top">Register</a>.<br/>Nov 19, 2010, 7:23pm </font><br /></p> Heres a screenshot that may help, as you can see I have easily changed the target of the link to="iframe1" using firebug, but I need to hardcode a script in my website that does this automatically after the iframe has loaded the forums page. http://img191.imageshack.us/img191/7264/26796014.jpg Thanks to for any help. I'm kind of new to javascript so forgive me for my ignorance. Is their anyway to track right mouse click within an iframe that is linked to an external site (i.e. www.nbc.com)? I'm trying to see if I can have a alert window say "This is an image" when i right click on an image within the iframe. Hello, First time on the forum and I am admittedly a complete noob, so forgive me for any grievous misconceptions. I am a teacher trying to create a bulletin board on my website where students, teachers, and parents can post messages. I am trying to use the site linoit.com I am trying to embed that site on my website using an iframe url: http://www.capretto.net/stickyboard.shtml My problem is that when you go to the message board on my site it asks your for a username and password to login to access my message board from linoit. I was hoping there is a scripts or other trick that will auto fill the username and password when the page loads so that the message board opens automatically. Not too worried about privacy, but I could distribute the username and password to all interested parents, teachers, etc. but in my experience one more step between students and the information they need can be the difference between them not receiving the info. I'd be happy to give any contributors credit on my site for their coding help. Thanks in advance. Hey guys. Is there any any ANY way to read highlighted text of in an iframe that is displaying an external server / site? Say you select some text in the iframe and click a button outside of the iframe that prints the selected text to a textbox? Really really would love to do this or any ANY workaround. This really sucks that its a security measure by default that doesn't allow this!! Ugh! I am creating chat application.I have friend list with whom login user can chat.onclick of user name i want to open different div in which i can load my chat page.Can anyone suggest me javascript for this task.
Good day all I have a contact form that opens up in a iframe on my home page. I have a second page with a link for contact and I would like to know If their is a javascript that when I press the contact link on the second page that it can go to the home page and open the iframe for the cntact form. Please note I do not know javascript I am trying to learn it. Thank you Shoutout I have a PARENT HTML page. Within it, there is an iFrame. Let us call page inside of iFrame is CHILD. I would like to following things: 1. When click button in CHILD, A NEW full size page opens and mouse focus moves to NEW. I used following scripts: function openFullWin(urlPara) { var windowFeatures = 'menubar=1,modal=0,resizable=1,scrollbars=1,status=1,toolbar=1,width=' + screen.availWidth + ',height=' + screen.availHeight + ',left=0,top=0'; var winNew = window.open(urlPara, '', windowFeatures); winNew.focus(); this.blur(); } In Firefox, if only PARENT widow there. It works property. However, if there is another window there, the focus moved to that window rather than the NEW. In IE, if there is another window there, the NEW open as a tab in that window, rather than as tab in PARENT. 2. When click button in CHILD, A NEW full size page opens and mouse focus moves to NEW. At meantime, the CHILD changes to a NEWCHILD page, but not on focus. I am never being able to do this. Please help. 3. When click button in CHILD, A NEW full size page opens to replace PARENT. Of course, the CHILD disappeared too. I am never being able to do this. Please help. Thank you in advance for your help with this. I have two pages. One page with thumbnails and another page with the actual gallery. On the gallery.html page I can scroll to my 5th image in the list by the following code: onclick="myScroll.scrollToPage(5,5)" I want to achieve this same effect from the index.html file into the gallery.html file. I have tried using anchored links like #image5, but that just messes up the page and the iscroll script I am working off of. Thank you again anyone who can help. Hi, is it possible to make a external javascript link by giving all the external links a class name then use getelementbytagname in the js file with a function to alert the hes leaving the website and let him choose if he wants to stay or leave. well thats what im trying to do but i dont know how to write the function for it maybe i could get a suggestion or a link to agood tutorial. / thanks lisa Hi, I am using a password protection javascript code that works very well, but my problem is that I would like to edit the code so that the ".html" page will open inside an iframe on the main page. I think the code "window.location=verification+extension" needs to be edit to indicate the iframe that I want the html page to open in. The complete code is below in bold and parts of code in red text is where I think I need to edit, but I don't know how to edit the code to do what I want. Can anyone please Help Me, Thanks to all that respond. <!-- var pass=new Array() var t3="" var lim=7 pass[0]="TLMXe8VqAwsAllw" pass[1]="YeWAc9pfP1rmGrA" pass[2]="M8ljslaPqg0mQQp" pass[3]="SRdDwXWa0LSsGB" pass[4]="83I2WyO06m3aUjs0" pass[5]="453I2WyO06m3aUjs" var extension=".html" var enablelocking=0 var numletter="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" var temp3='' var cur=0 function max(which){ return (pass[Math.ceil(which)+(3&15)].substring(0,1)) } function testit(input){ temp=numletter.indexOf(input) var temp2=temp^parseInt(pass[phase1-1+(1|3)].substring(0,2)) temp2=numletter.substring(temp2,temp2+1) return (temp2) } function submitentry(){ t3='' verification=document.password1.password2.value phase1=Math.ceil(Math.random())-6+(2<<2) var indicate=true for (i=(1&2);i<window.max(Math.LOG10E);i++) t3+=testit(verification.charAt(i)) for (i=(1&2);i<lim;i++){ if (t3.charAt(i)!=pass[phase1+Math.round(Math.sin(Math.PI/2)-1)].charAt(i)) indicate=false }0 if (verification.length!=window.max(Math.LOG10E)) indicate=false if (indicate) window.location=verification+extension else alert("Invalid password. Please try again") } //--> Hi all. First post so please be gentle. My sites has a menu on the home page linking to a dozen other pages. My intention is to open those items into a main iframe also on the home page. I have put the <base target="iframe" > in the <Head> area and all seems to work in Opera but Internet Explorer and Firefox will both open new windows instead of loading into the iframe. Having said that. Links from WITHIN the iframe will open correctly in all browsers. Ideas in newbie-speak very much appreciated Regards, Phil I have a website that is using ajax to keep the page up to date with the database information. I call this page through a file called start.php. Once index.php is loaded it has a menu with selections. I then want it to call a page called query.php in an iframe to update the information, but not open a new window. In the iframe the query.php will run and then redirect itself to blank.php. The code is as follows and any help would be much appreciated. I have tried several methods of doing this and they have been commented out because they didn't work or didn't do what I wanted them to do. I do not want to use window.open since IE doesn't work well with it. window.open does work by pop up windows but I want to stay away from them. The main code I am looking to get help on is in red under start.php. In start.php I will include the entire file. In index.php I'm only going to include the main sections I use for this snippit. In query.php I'm not going to include query.php since I beleive this file isn't important for this snippit. start.php Code: <html> <head> <title>Countries At War!</title> <body style="background-color:#B0C4DE;"> <script language="JavaScript" type="text/javascript"> //Gets the browser specific XmlHttpRequest Object function getXmlHttpRequestObject() { if (window.XMLHttpRequest) { return new XMLHttpRequest(); //Not IE } else if(window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP"); //IE } else { //Display your error message here. //and inform the user they might want to upgrade //their browser. alert("Your browser doesn't support the XmlHttpRequest object. Better upgrade to Firefox."); } } //Get our browser specific XmlHttpRequest object. var receiveReq = getXmlHttpRequestObject(); //Initiate the asyncronous request function sayHello() { //If our XmlHttpRequest object is not in the middle of a request, start the new asyncronous call. if (receiveReq.readyState == 4 || receiveReq.readyState == 0) { //Setup the connection as a GET call to SayHello.html. //True explicity sets the request to asyncronous (default). receiveReq.open("GET", 'index.php', true); //Set the function that will be called when the XmlHttpRequest objects state changes. receiveReq.onreadystatechange = handleSayHello; //Make the actual request. receiveReq.send(null); } } //Called every time our XmlHttpRequest objects state changes. function handleSayHello() { //Check to see if the XmlHttpRequests state is finished. if (receiveReq.readyState == 4) { //Set the contents of our span element to the result of the asyncronous call. document.getElementById('span_result').innerHTML = receiveReq.responseText; } } function openMenu(query) { var myString = 'query.php?' + query; // window.open(myString, 'linkname', 'title=no, height=465, width=400, left=550, top=150, location=yes, resizable=no, menubar=no, scrollbars=no') //document.getElementById('engine').src = myString; //document.getElementById('engine').setAttribute('src',myString;); //top.frames['engine'].location.href = myString; pausecomp(1000); sayHello(); } function pausecomp(millis) { var date = new Date(); var curDate = null; do { curDate = new Date(); } while(curDate-date < millis); } </script> </head> <body> <a href="javascript:sayHello();">Say Hello</a><br /> <iframe src="blank.php" MarginWidth="0" transparent="yes" width="30" height="25" frameborder="0" scrolling="no" name="engine"> UPGRADE YOUR BROWSER</iframe> <span id="span_result"></span> <body onLoad="sayHello();"> </body> </html> index.php Code: <table width="100%" border="2" bordercolor="Black"> <tr><center> <td><center><a href="javascript:void(0);" onclick="javascript: openMenu('menulevel1=1');">Home</a></td> <td><center><a href="javascript:void(0);" onclick="javascript: openMenu('menulevel1=2');">Jobs</td> <td><center><a href="javascript:void(0);" onclick="javascript: openMenu('menulevel1=3');">Travel</td> <td><center><a href="javascript:void(0);" onclick="javascript: openMenu('menulevel1=4');">Fight</td> <td><center><a href="javascript:void(0);" onclick="javascript: openMenu('menulevel1=5');">Inventory</td> <td><center><a href="javascript:void(0);" onclick="javascript: openMenu('menulevel1=6');">Properties</td> <td><center><a href="javascript:void(0);" onclick="javascript: openMenu('menulevel1=7');">Rewards<?php if($db_field['rewardpoints'] >= "1") print "(". $db_field['rewardpoints'] . ")";?></td> <td><center><a href="javascript:void(0);" onclick="javascript: openMenu('menulevel1=8');">Profile<?php if($db_field['profilepoints'] >= "1") print "(". $db_field['profilepoints'] . ")";?></td> <td><center><a href="javascript:void(0);" onclick="javascript: openMenu('menulevel1=9');">Alliances</td> <td><center><a href="javascript:void(0);" onclick="javascript: openMenu('menulevel1=10');">Options</td> </tr></center> </table> Thanks in advance for all the help. I am trying to have a text link above Google Maps link to a marker on my map. When the link is clicked, the map will automatically center itself on the marker. I already have the custom markers and locations, I am just not that good with Javascript and jQuery to figure it out. I tried to use Code: <a href="javascript: map.panTo(new LatLng(25.2, 105.7))">Mexico</a> and the link shows up, but nothing happens. Here is my code: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style type="text/css"> body { font-family: Helvetica, Arial, sans-serif; font-size:10px; margin:0; } #content { } </style> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> <script type="text/javascript"> function initialize() { var latlng = new google.maps.LatLng(39.346246,-76.624446); var settings = { zoom: 15, center: latlng, mapTypeControl: true, mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU}, navigationControl: true, navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL}, mapTypeId: google.maps.MapTypeId.ROADMAP}; var map = new google.maps.Map(document.getElementById("map_canvas"), settings); var contentString = '<div id="content">'+ '<div id="siteNotice">'+ '</div>'+ '<div id="bodyContent">'+ '</div>'; var infowindow = new google.maps.InfoWindow({ content: contentString }); var loyolaImage = new google.maps.MarkerImage('images/Loyola.png', new google.maps.Size(100,50), new google.maps.Point(0,0), new google.maps.Point(50,50) ); var loyolaShadow = new google.maps.MarkerImage('images/logo_shadow.png', new google.maps.Size(130,50), new google.maps.Point(0,0), new google.maps.Point(65, 50)); var loyolaPos = new google.maps.LatLng(39.3462326,-76.624446); var loyolaMarker = new google.maps.Marker({ position: loyolaPos, map: map, icon: loyolaImage, shadow: loyolaShadow, title:"Loyola", zIndex: 3}); var jhuImage = new google.maps.MarkerImage('images/Jhu.png', new google.maps.Size(150,50), new google.maps.Point(0,0), new google.maps.Point(50,50) ); var jhuShadow = new google.maps.MarkerImage('images/logo_shadow.png', new google.maps.Size(130,50), new google.maps.Point(0,0), new google.maps.Point(60, 50) ); var jhuPos = new google.maps.LatLng(39.329157,-76.620477); var jhuMarker = new google.maps.Marker({ position: jhuPos, map: map, icon: jhuImage, shadow: jhuShadow, title:"Johns Hopkins", zIndex: 2 }); var fellsImage = new google.maps.MarkerImage('images/FellsPoint.png', new google.maps.Size(150,50), new google.maps.Point(0,0), new google.maps.Point(50,50) ); var fellsShadow = new google.maps.MarkerImage('images/logo_shadow.png', new google.maps.Size(130,50), new google.maps.Point(0,0), new google.maps.Point(60, 50) ); var fellsPos = new google.maps.LatLng(39.28231,-76.593611); var fellsMarker = new google.maps.Marker({ position: fellsPos, map: map, icon: fellsImage, shadow: fellsShadow, title:"Johns Hopkins", zIndex: 4 }); var towsonImage = new google.maps.MarkerImage('images/Towson.png', new google.maps.Size(150,50), new google.maps.Point(0,0), new google.maps.Point(50,50) ); var towsonShadow = new google.maps.MarkerImage('images/logo_shadow.png', new google.maps.Size(130,50), new google.maps.Point(0,0), new google.maps.Point(60, 50) ); var towsonPos = new google.maps.LatLng(39.3322248,-76.610944); var towsonMarker = new google.maps.Marker({ position: towsonPos, map: map, icon: towsonImage, shadow: towsonShadow, title:"Towson", zIndex: 1 }); google.maps.event.addListener(companyMarker, 'click', function() { infowindow.open(map,companyMarker); }); } </script> <script> google.maps.event.addDomListener(controlUI, 'click', function() { map.setCenter(chicago) </script> </head> <body onload="initialize()"> <div id="map_canvas" style="width:500px; height:300px"></div> <a href="javascript: map.panTo(new LatLng(39.393248,-76.610944))">Towson</a> </body> </html> How can I let link page open using IE? for example, I open a webpage using firefox or chrome/opera/safari. when I click the link, open the link using IE <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head2" runat="server"> </head> <body> <a href="#" onClick="window.showModalDialog ('http://www.google.ca','','width=600,height=600','screenx=200','screeny=200')"><img src="images/benemanc-01th.jpg" alt="img-01" width="125" height="155" class="thumb" style="display:inline"></a> </body> </html> Many thanks T I have a php page which uses the following javascript code to open another page (The users profile page) and alos carry over the userID (dUid) Code: var userProfileUrl = chatProfileUrl+dUid.replace(/_/gi,""); document.getElementById('userdetails').innerHTML += "<span class='userinfo' onClick=\"window.open('"+userProfileUrl+"','"+dUid+"')\"><img id='profile' style='cursor:pointer;vertical-align:middle;padding-top:4px;' src=images/zoom.png> View Profile</span></br>"; I wanted to add to the menu another image link so I copied the same coding, but I do not know where to place the URL target that I want opened. I know I want the userID (dUid) also to follow this link as well. If I want the coding below to act in the same manner as the coding above, but instead open a page called /gift.php, where do I set the Url? Code: document.getElementById('userdetails').innerHTML += "<span class='userinfo' onClick=\"window.open('"+userProfileUrl+"','"+dUid+"')\"><img id='profile' style='cursor:pointer;vertical-align:middle;padding-top:4px;' src=images/gift.png> Send Gift</span></br>"; Hi All, Im a newbie when it comes to Javascript and trying to learn as I go along. I am working on an internal work site. In the site I have a text box and on entering a specific code I want it to open a new page that links to a document that has the same name. ie. if user types red, I want it to find the document red.html in a folder. To make my colleagues job easier, I want the text box to autocomplete. Below is a section of the code I plan to use Code: <script> var arrValues = ["red", "orange", "yellow", "green", "blue", "indigo", "violet", "brown"]; </script> </head> <body> <h2>Autocomplete Textbox Example</h2> <p>Type in a color in lowercase:<br /> <input type="text" value="" id="txt1" onkeypress="return autocomplete(this, event, arrValues)" /></p> </body> </html>Can anyone help me to modify this to: 1) link the text entered to the document I want opened 2) open this document upon 'enter' pressed If anyone can provide help it will be greatly appreciated. Thanks Glen |