coolcat50 0 Report post Posted November 11, 2007 Hello! I am wondering whether or not it is possible to have a dynamic iframe that changes when a link is pressed. I believe I know a way for this to be done with the php $_GET variable and only using a certain part of the url. I am wondering if this would maybe work. I want this for a chatbox that will have a little side menu for BBCode reference and a notepad. <?phpif($_GET['toolbar'] == 'bbcode'){//display my bbcode reference page here}if($_GET['toolbar'] == 'notepad'){//display my notepad page here}if($_GET['toolbar'] == 'smilie')//display my smilie page here}else{?><!-- Display my chatbox here --><!-- IFRAME code --><iframe src="thispage.php?toolbar"></iframe><?php}?> Share this post Link to post Share on other sites
jlhaslip 4 Report post Posted November 11, 2007 why not? Problem with using php would be that it requires a refresh from the Server. Javascript or Ajax could do it without the full refresh.But utilizing the Iframe in this manner should work, or simply a div, maybe?http://forums.xisto.com/no_longer_exists/ Share this post Link to post Share on other sites
coolcat50 0 Report post Posted November 12, 2007 (edited) Well, I don't really understand AJAX and I can't copy and paste code so the XML object will be annoying to use and with a link the page would automatically refresh. Maybe a Javascript pop-up could work, but I want it to show up inside the page. Maybe Javascript style changes could do it. Or something.Also, with an iframe I can have it load with a different file. That would probably be required. Also, I could always use AJAX with PHP to do it. I just gotta learn how to lol. Edited November 12, 2007 by coolcat50 (see edit history) Share this post Link to post Share on other sites
galexcd 0 Report post Posted November 13, 2007 If I understand what you want to do correctly, you want to have the page display the iframe if the toolbar get variable isn't 'smilie', 'notepad', or 'bbcode'. And the iframe is going to reference this page except with those variables? Well if that is the case it looks like you are missing quite a few else'sTry This: <?phpif($_GET['toolbar'] == 'bbcode'){//display my bbcode reference page here}else if($_GET['toolbar'] == 'notepad'){//display my notepad page here}else if($_GET['toolbar'] == 'smilie')//display my smilie page here}else{?><!-- Display my chatbox here --><!-- IFRAME code --><iframe src="thispage.php?toolbar"></iframe><?php}?> If you don't do this you will have an iframe inside an iframe inside an iframe inside an iframe... well you get the point. Infinite loop of iframes. Share this post Link to post Share on other sites
coolcat50 0 Report post Posted November 13, 2007 Thanks! That is exactly what I am wanting Share this post Link to post Share on other sites
galexcd 0 Report post Posted November 13, 2007 (edited) I actually found some other problems in the code.First you didn't put an open bracket after if($_GET['toolbar'] == 'smilie') but you put a closing bracket.Second you didn't set the variable toolbar in the iframe. I don't know if that was just an example, but if you don't set it it will just reload the actual page. I just set toolbar to notepad as an example. <?phpif($_GET['toolbar'] == 'bbcode'){//display my bbcode reference page here}else if($_GET['toolbar'] == 'notepad'){//display my notepad page here}else if($_GET['toolbar'] == 'smilie'){//display my smilie page here}else{?><!-- Display my chatbox here --><!-- IFRAME code --><iframe src="thispage.php?toolbar=notepad"></iframe><?php}?> Also quick note, spaces and newlines don't change php at all. You don't have to write statements like if and else out like this:}else{}else{ works just fine. It's all just depending on your style, but most people prefer the latter. Edited November 13, 2007 by alex7h3pr0gr4m3r (see edit history) Share this post Link to post Share on other sites
coolcat50 0 Report post Posted November 13, 2007 Well, my style is new spaces for me to read easier due to my using my Nintendo Wii for management. Also, I don't want the iframe constantly being one part but change. So, I just used toolbar to show that the variable is part of the url and it changes. I probably need to add a base tag though for the links right? AJAX would probably be better anyway or just plain Javascript. And yes that was an example code. Share this post Link to post Share on other sites
who? 0 Report post Posted November 14, 2007 (edited) There's a much simpler way... Using the "target" attribute on your links. Example: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://forums.xisto.com/no_longer_exists/ xmlns="http://forums.xisto.com/no_longer_exists/ Title Here</title></head><body><a href="bbcode.htm" target="toolbar">BBCode</a><a href="notepad.htm"target="toolbar">Notepad</a><a href="smilie.htm" target="toolbar">Smilie</a><iframe name="toolbar" src="firstVisitIframeSource.htm"></iframe></body></html> ADDING:By the way... Obviously, no PHP coding is needed in the example... Edited November 14, 2007 by who? (see edit history) Share this post Link to post Share on other sites
coolcat50 0 Report post Posted November 16, 2007 Well, it doesn't require PHP, but it does require extra files that can clog up my file manager. With the PHP $_GET global I can create the same effect with one file. That could even decrease load times.(I think.) Share this post Link to post Share on other sites
who? 0 Report post Posted November 19, 2007 Well, it doesn't require PHP, but it does require extra files that can clog up my file manager. With the PHP $_GET global I can create the same effect with one file. That could even decrease load times.(I think.)I really don't think it would decrease load times (even if it does, I believe it would be irrelevant). So... Why would the extra files clog up your file manager?Now: it depends whether you want a fat or a thin client.If you want a fat client, I would suggest Javascript (I had written a Javascript script for you before I came up with the "target" attribute) to dinamically change a div's inner HTML, instead of using an iframe. This would be a way to only use one file, since the HTML code would be all on the javascript (still don't get why it must be a one-file script; Javascript would also be able to load the html from external files, but that way it would work as an iframe).If you want a thin client, then you should continue to use php, but this will create a fat server, because this will make the server process more information. That would also cause an unnecessary refresh.By the way... I couldn't understand whether you want the iframe to appear ONLY IF the get var isn't any of the three pages or if you want the iframe to appear and have one of the code segments of your page as source.Eg:Situation A:Page 1;Or page 2;Or page 3;Or Iframe.Situation B:Code that will be used to generate a page for the iframe, meaning that it will be generated if the get var is defined as being one of the three pages;Chatbox.Iframe with src="samePageWhereItIsLocated.php?toolbar="oneOfThreePages"" Share this post Link to post Share on other sites
coolcat50 0 Report post Posted November 19, 2007 I need an Iframe that appears when a link is pressed like.Chat Here Iframe When Link is PressedLink Link Link Share this post Link to post Share on other sites
who? 0 Report post Posted November 19, 2007 (edited) I need an Iframe that appears when a link is pressed like.Chat Here Iframe When Link is PressedLink Link LinkWhat about the "one file only" situation?If you want the iframe to appear only if the link is pressed, you can use Javascript and DOM to make an iframe with no width nor height.Eg:Chat Here. Iframe here, but, as width and height are set to 0 it doesn't appear.Link here (when pressed, it will set some width and height and set notepad as the iframe src.Link here (when pressed, it will set some width and height and set smilie as the iframe src.Link here (when pressed, it will set some width and height and set bbcode as the iframe src.You can also give some width and height to the iframe from the beggining, but using css make it invisible (display: none), and when a link is pressed, it will just set the iframe src and set it to be displayed.Do you think any of the solutions is good for your problem? Notice that it would require more than one file, because you're using AN IFRAME!!! If you want to only use one file and if you want the refresh thing to happen... Then use Div instead of an iframe, because if you're using an iframe you'll always need more that one file... That's why I don't understand what's the thing with more that one file.EDIT: "display: none". Edited November 19, 2007 by who? (see edit history) Share this post Link to post Share on other sites
coolcat50 0 Report post Posted November 19, 2007 Well, I do not quite know how to use a div like that. The innerHTML object could work with PHP include. There probably are better ways though. And I would prefer CSS over using DOM. Share this post Link to post Share on other sites
who? 0 Report post Posted November 19, 2007 (edited) Well, I do not quite know how to use a div like that. The innerHTML object could work with PHP include. There probably are better ways though. And I would prefer CSS over using DOM.Again, that would require the above mentioned refresh. Personally, I wouldn't use that method, because a frequent user hates to wait for a page loading (which is unnecessary, since it only add html content to a div, what could have been done dinamically, without the refresh). I got it. You like PHP. But PHP is a server language. Stuff that needs to be changed quickly (as the iframe src) need to be done either on a client language (Javascript) or through the target attribute.So... This is just a matter of choice. If you feel you're more familiar with PHP, then do it, although I don't advice you to.My question is... Is your problem solved? Or do you still need help with it?By the way... To use a div with innerHTML... Simply ID the div and through Javascript (and obviously, DOM), set the innerHTML to the things you want (that would need the HTML to be written on Javascript).E.g.: <html><head><script type="text/javascript">function divInnerHTML(divHTML) {divtodefine = document.getElementById('divswap');switch(divHTML) {case "smilie":divtodefine.innerHTML = "Smilie HTML CODE HERE";break;case "bbcode":divtodefine.innerHTML = "BBcode HTML CODE HERE";break;}}</script></head><body><a href="java script:divInnerHTML('smilie')">Smilie</a><a href="java script:divInnerHTML('bbcode')">BBcode</a><div id="divswap">Predefined HTML</div></body></html> Edited November 19, 2007 by who? (see edit history) Share this post Link to post Share on other sites
coolcat50 0 Report post Posted November 19, 2007 yeah im gonna do it with javascript when i get my shoutbox set up. thanks alot! Share this post Link to post Share on other sites