d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Call Command From Within Iframe > 35fg For Working Answer :)
Add Reply New Topic New Poll
Member
Posts: 476
Joined: Dec 2 2007
Gold: 35.00
Sep 16 2012 12:50pm
If this works properly on the parent frame
Code

OnClick="try{ if( !parent.GB ) return GB_showCenter('Show Cart', 'http://localhost/index2.php?page=shop.cart&option=com_virtuemart&Itemid=1', 500, 600);} catch(e) { }"


How can I make the command work from within an Iframe?


Something like this -
Code

<a OnClick="parent.(try{ if( !parent.GB ) return GB_showCenter('Show Cart', 'http://localhost/index2.php?page=shop.cart&option=com_virtuemart&Itemid=1', 500, 600);} catch(e) { })">Click Here</a>


35FG for anyone who can give me an answer that works
Banned
Posts: 2,525
Joined: Jan 2 2012
Gold: 0.01
Warn: 10%
Sep 16 2012 12:51pm
Simply put, you can't. If you open some kind of error console you should get errors telling you you're trying to do is forbidden.

What you can do, is to make kind of message passing system between iframe and parent. Either with server side (ajax) or e.g. checking document.location.hash for changes and calling method when required. And then iframe/parent can change this value by changing it's location and appending #message

This post was edited by ikusus on Sep 16 2012 12:57pm
Member
Posts: 476
Joined: Dec 2 2007
Gold: 35.00
Sep 16 2012 01:14pm
Here is a Demo of what I'm trying to get twords
http://xso-online.com/chessfactory/
The Iframe was simply an attempt to try and solve this problem

If you Add something to the cart, you can see the button "Checkout" if you click it - then a box comes up enabling you to enter your information in.

The reason I had to use an Object Tag was because on the left you can see "MagicZoom" if you click on a product image, well if i use an <img src""> tag, if I add anything into the src such as <img src="test.gif"> the virtuemart template crashes, and you can't see anything within the table on the template.
- I disable MagicZoom and everything functions properly

So I used an <Object> tag, however... if you view it in internet explorer.... there are scrollbars on the object area, and the object isn't clickable

Once again, in order to reproduce the problem, you need to add something to your cart then the checkout button will appear using ajax

Heres the Code used in the template:
Code
<?php if (!$empty_cart && !$vmMinicart) { ?>
   <br style="clear:both" /><div style="float: left;">

<OBJECT style="cursor:pointer;margin-left:-8px;margin-top:-3px;" DATA="tst.ad2" onclick="try{ if( !parent.GB ) return GB_showCenter('Show Cart', 'http://localhost/index2.php?page=shop.cart&option=com_virtuemart&Itemid=1', 500, 600);} catch(e) { }" TYPE="image/gif" TITLE="Show Cart" width=111 height=31 ></OBJECT>



   </div>            <div style="float: right;"><div><?php echo $delete_cart ?></div></div><br/>







I'd also like to know how to completely remove the "Flashing Yellow" function because it dosen't work in internet explorer and conflicts with another function regarding the lower table <iframe>

this is the code the produces that flashing yellow
Code
/**
* This function searches for all elements with the class name "vmCartModule" and
* updates them with the contents of the page "shop.basket_short" after a cart modification event
*/
function updateMiniCarts() {
var callbackCart = function(responseText) {
 carts = $$( '.vmCartModule' );
 if( carts ) {
  try {
   for (var i=0; i<carts.length; i++){
    carts[i].innerHTML = responseText;
 
    try {
     color = carts[i].getStyle( 'color' );
     bgcolor = carts[i].getStyle( 'background-color' );
     if( bgcolor == 'transparent' ) {
      // If the current element has no background color, it is transparent.
      // We can't make a highlight without knowing about the real background color,
      // so let's loop up to the next parent that has a BG Color
      parent = carts[i].getParent();
      while( parent && bgcolor == 'transparent' ) {
       bgcolor = parent.getStyle( 'background-color' );
       parent = parent.getParent();
      }
     }
     var fxc = new Fx.Style(carts[i], 'color', {duration: 1000});
     var fxbgc = new Fx.Style(carts[i], 'background-color', {duration: 1000});

     fxc.start( '#222', color );    
     fxbgc.start( '#fff68f', bgcolor );
     if( parent ) {
      setTimeout( "carts[" + i + "].setStyle( 'background-color', 'transparent' )", 1000 );
     }
    } catch(e) {}
   }
  } catch(e) {}
 }
}
var option = { method: 'post', onComplete: callbackCart, data: { only_page:1,page: "shop.basket_short", option: "com_virtuemart" } }
new Ajax( live_site + '/index2.php', option).request();


}


This post was edited by exo232 on Sep 16 2012 01:15pm
Member
Posts: 476
Joined: Dec 2 2007
Gold: 35.00
Sep 16 2012 01:22pm
I'm an idoit... I fixed it, this is how...

Code
<img src="tst.ad2" style="cursor:pointer;margin-left:-8px;margin-top:-3px;" onclick="try{ if( !parent.GB ) return GB_showCenter('Show Cart', 'http://localhost/index2.php?page=shop.cart&option=com_virtuemart&Itemid=1', 500, 600);} catch(e) { }" TYPE="image/gif" width=111 height=31 >


MagicZoom is searching for extensions so I renamed the file to ".ad2" and used an img tag - it worked.

MagicZoom also still works... however still looking for an answer on the second question
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll