Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: change iframe content and parent window content from single click in iframe window

  1. #1
    Join Date
    May 2014
    Posts
    203
    Thanks
    28
    Thanked 5 Times in 5 Posts

    Default change iframe content and parent window content from single click in iframe window

    I have an iframe on a page with a series of <A id="#1"><A id="#2"> etc, i'd like to make one of them also change the content in the parent window at the same time, in just one click. in other words, window.top.location.href and id="#2" in one link statement. the top window would change at the same time as the id="2#". is that possible? i know with the old html frames,you could load different html pages in different frames of the page with one click, which was incredibly useful, but i'm not finding a similar script for iframes.

    wait, i'm not thinking about this correctly, if parent window changes, iframe would also change if not included (and even if included i need a way to pass the id series inside the iframe <a id=#whatever" to the new (yet same, iframe). so if i include iframe on parent window that has changed, ......
    ugh. okay, with the old method of jumping to anchor links in/out of page, you could append the #whatever to the end the address. like blahblahpage.html#whatever. they messed all that up with their html5 changes.

    i'm guessing the only way to resolve this is to window.top with the single click and just have the iframe on the new window.top loaded with the new id already in it.
    sorry about the mess. you can skip this crazy confused question
    Last edited by jundo12; 04-28-2017 at 04:54 PM.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,371
    Thanks
    77
    Thanked 3,421 Times in 3,382 Posts
    Blog Entries
    12

    Default

    This actually can be done. I would use a query string attached to the url. That could be read by a script on the new top page and give an indication, or the entire url to be loaded into the iframe on the new top page. But same origin restrictions might apply. Probably not though. But sites/pages that don't allow themselves to be loaded into frame/iframe would cause this scheme not to work as desired.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,371
    Thanks
    77
    Thanked 3,421 Times in 3,382 Posts
    Blog Entries
    12

    Default

    Here's a demo - the from page (call it anything you want):

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title>Loader</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    </head>
    <body>
    <a href="loadintoiframe.htm?url=http%3A%2F%2Fwww.dynamicdrive.com%2F">A Page with DD in an iFrame</a>
    </body>
    </html>
    The page that will perform this "miracle" (in this example, it should be saved as "loadintoiframe.htm"):

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <title>Load Into iFrame</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    </head>
    <body>
    <iframe name="targetframe" src="about:blank" width="300" height="300" scrolling="auto" frameborder="1"></iframe>
    <script>
    (function(){
    	var s = window.location.search, i, q;
    	s = s.split(/[\?&]/); i = s.length;
    	while(--i > -1){
    		q = s[i].split('=');
    		if(q[0] === 'url'){
    			window.frames.targetframe.location.replace(unescape(q[1]));
    			break;
    		}
    	}
    })();
    </script>
    </body>
    </html>
    Though tested and works, it's just a rough idea off the top of my head from stuff I've seen before. Any questions, just let me know.
    Last edited by jscheuer1; 04-29-2017 at 04:20 AM. Reason: code improvement
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. The Following 2 Users Say Thank You to jscheuer1 For This Useful Post:

    jundo12 (04-30-2017)

  5. #4
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,734
    Thanks
    46
    Thanked 216 Times in 209 Posts
    Blog Entries
    53

    Default

    If I understand the question well, then this would also be possible.
    Same origin restrictions don't apply.

  6. The Following User Says Thank You to molendijk For This Useful Post:

    jundo12 (04-30-2017)

  7. #5
    Join Date
    May 2014
    Posts
    203
    Thanks
    28
    Thanked 5 Times in 5 Posts

    Default

    wow thanks guys.
    i am trying to simulate a japanese roleplaying game style , featuring a turn-based battle system, in a regular html page using an iframe for messages such as "you were hit for 1 pt of damage' or "the enemy was hit for 1 pt of damage" , etc. i was trying to keep as many of the events of the battle on the same page to avoid the screen flashes that result from changing html pages. as it turned out, i still had to change html pages twice during just the first round of battle. le mew, le sigh.

  8. #6
    Join Date
    May 2014
    Posts
    203
    Thanks
    28
    Thanked 5 Times in 5 Posts

    Default

    note: trying to simulate random events and score keeping with html, css and javascript, is no easy task. i'm not using a game engine for this. i'm attempting to make the entire thing with just freely available bits of random genius of other coders, like mr. jscheuer1. one thing i did was find a random page generator, which on button click, picks whether the attack hits, crits or misses by loading the randomly picked corresponding page for hit, crit or miss.. then i have to change graphic used for the health of the player and the health of the monster, manually and the corresponding animations for the attacks, each time. since there are 3 possible attack types, and each of those has 3 randomly generated possibilities (hit, crit or miss), i will end up making hundreds of pages, for just one battle. lol i'm sure there's an easier way but i am not a coder. when i look at javascript codes, particularly complex ones, it all just reads like a foreign language i don't understand.
    Last edited by jundo12; 04-30-2017 at 12:30 AM.

  9. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,371
    Thanks
    77
    Thanked 3,421 Times in 3,382 Posts
    Blog Entries
    12

    Default

    Do you have a specific question? In any case, if there are only three possible outcomes, you should only need three pages, at least for the outcomes.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. #8
    Join Date
    May 2014
    Posts
    203
    Thanks
    28
    Thanked 5 Times in 5 Posts

    Default

    Quote Originally Posted by jscheuer1 View Post
    Do you have a specific question? In any case, if there are only three possible outcomes, you should only need three pages, at least for the outcomes.

    even the question is hard to decide how best to ask it. if there are 3 attack types (one ranged melee, two magic based) and each of those can be either a hit,miss or crit, and the player can also heal their own character, how do i keep track of all that? my theory was that i would have to make at least two pages for each attack round (player attacks, monster attacks), one for each attack type (ranged melee, magic 1 and magic 2) and for each random event (hit, crit or miss) and do so for each pt of health the monster had and lost and for each pt of health the player had and lost and also healed. it starts to add up. because html is so linear, and i don't incorporate a data storage technique, each event has to be done manually. in effect, every possible combination of the three attack types + heal, would have to have a page generated for it, encompassing potentially, at the very least, 20 rounds (and that's being generous since some of those rounds will be random misses and some will be heals. and its only 20 rounds if the player's character landed a critical attack 20 times in a row lol....not gonna happen with a random page script with only 3 possible choices, all three of which have the same chance of rolling . critical attack does twice as much damage as normal hit. )

    it's boggling my brain. i managed to make the first round (player attacks + animation, monster attacks + animation, changed health bar graphics to indicate damage done to player health and monster health, and return for second round. now if the player pushes the same button, i have to generate a page in advance for that potentiality, if they push a different button i have to make a page for that in advance, and i have to make the page that shows either a hit miss or crit. i also have to make pages where they don't push attack at all and instead just heal themselves over and over lol doh. thats like......i'm boggled.


    i realize some things are re-usable, such as the ranged melee hit, crit or miss pages, the magic 1 hit crit and miss and the magic 2 hit crit or miss, the animations themselves, once created are re-usable, but i still have to make the html page that will hold and depict the event - the attack animations, the heal animation, the health bar status changes,if any, each time an attack or heal transpires which is almost totally out of my control. the person playing the game by pressing the buttons is making the bulk of the choices. i can't even calculate how many individual html pages would be necessary to render all of that in a game like way so that any potential button choices made and random events, would have a corresponding page to support it.
    Last edited by jundo12; 04-30-2017 at 06:29 AM.

  11. #9
    Join Date
    May 2014
    Posts
    203
    Thanks
    28
    Thanked 5 Times in 5 Posts

    Default

    i've counted up how many potential pages had to be made for first round:
    1. melee attack hit
    2. melee attack crit
    3. melee attack miss
    4. magic 1 hit
    5. magic 1 crit
    6. magic 1 miss
    7. magic 2 hit
    8. magic 2 crit
    9. magic 2 miss
    10. heal
    11. page to hold player attack
    12. page to hold monster attack
    13. page to hold beginning of battle
    14. page to hold beginning of next round.
    15. page showing results for player char attack
    16. page showing results for monster attack

    once the initial crits hits and misses for each attack type is created and the heal, they can be reused. so 6 new pages each round.
    multiply that by, at the very least 20 (extremely unlikely) and most likely over 35. that's how many individual pages i have to make to simulate one
    turn based battle, from beginning to end, in a browser window with nothing but html, css, a javascript random page generator, and a javascript auto page
    changer on a set timer delay. i don't mind making the pages and i realize some of them are reusable. what makes the amount of pages needed so high
    is that all the randomness is being simulated by each potential event being pre-generated by yours truly, beforehand. i have to simulate all possible combinations of
    button choices for 35-ish battle rounds. thats like 210 pages or thereabouts lol (and probably alot more)

    note: i've made it easier on myself by making the amount of damage be the same, regardless of attack type. so magic 1 will do same damage as melee attack or magic 2. etc the only variable is if its crit or hit or miss, i'm considering removing "miss" from the variables because it'll make the damage calculations tidier.
    Last edited by jundo12; 04-30-2017 at 07:27 PM.

  12. #10
    Join Date
    Nov 2014
    Location
    On A Scottish Island
    Posts
    432
    Thanks
    0
    Thanked 54 Times in 50 Posts

    Default

    If you start now and code four pages a day you'll easily be finished by early July. Good luck with the project.

Similar Threads

  1. Popup from Iframe to Position in Parent window not working
    By mfeola in forum Dynamic Drive scripts help
    Replies: 7
    Last Post: 09-25-2008, 09:47 PM
  2. dhtmlwindow - iframe closing window and changing parent window
    By georgie_b in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 03-09-2008, 06:52 PM
  3. Replies: 2
    Last Post: 04-14-2007, 12:39 PM
  4. Replies: 8
    Last Post: 01-15-2007, 08:59 PM
  5. Replies: 0
    Last Post: 06-03-2005, 07:00 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •