Dynamically resize an iframe depending on it’s content

June 9, 2010 at 1:36 pm In Web, Work, No Comments

A while back I figured out a neat trick to enable you to resize an iframe embedded on someone else’s page depending on the size of it’s contents.

The problem is this.

You have a widget that you want other people to be able to embed in the pages of their website, and you want to use an iframe to do this.  However the content of the iframe widget is dynamic, and the size of it can vary, depending on the content.  You want the iframe/widget to resize itself to suit the content.

Problem. There is NO way to resize an iframe of your content embedded on someone else’s page from WITHIN the iframe content itself.  No amount of JavaScript or clever twiddling in the page served up in the iframe will allow you to do this.  By design browsers wont let content from another domain affect the parent container.  It is far too insecure, this referred to as same origin policy.  If you are serving up content in the iframe from the same domain as the parent page, then you can just use JavaScript to do this.

Only the parent container can resize the iframe.  So seeing as the parent container is someone else’s page that you have no control over, how do you make it aware of the content in the iframe and tell it how to resize the iframe?

Solution.  You can do this simply by serving up a dynamic style sheet with the iframe code used to embed your widget.  This style sheet (CSS) served up by the same server as the widget content, and it knows what the dynamic content is in the iframe and can figure out how big the iframe needs to be.  This CSS file therefore needs to be a dynamically generated file, as it will need to do some server side calculations to figure out what the dimensions are.

Here is an example of the widget code you would supply.

<link href=”http://your.site/path/to/css.php?content_id=1234&dom_id=iframe_widget” rel=”stylesheet” type=”text/css” />
<iframe id=”iframe_widget” src=”http://your.site/path/to/content.php?content_id=1234″ frameborder=”0″ width=”100%” scrolling=”no”></iframe>

The style sheet will need to use some server side code to output the correct dimensions for the iframe element style.  Here is an example for dynamically generating this style.

<?php

$domId = $_GET["dom_id"];  //This is the dom element ID of the iframe to generate the style for
$content_id = $_GET["content_id"]; //This the unique identifier for the content being generated by the widget/iframe

/**

Using the $content_id, do some magic here to determine what the content is (customer details, list of products, photos etc), and calculate the height etc.  This is simple for things like a list of items where the height of the elements is fixed, but the number is variable.  If the widget is a combination of things that are dependent on font size, width of elements, white-space wrapping etc, it can get a little tricky, but in the end it is all just math.

**/

$elementHeight = $x * $y + 100;  //This is just an example.

?>

/* STYLE SHEET STARTS HERE */

#<?php echo $domId;?>
{
height: <?php echo $elementHeight;?>px;
overflow: hidden;
scroll: none;
}

That’s it.  Nice and simple-ish.  Only tricky if the content of the iframe wildly varies.

VendHQ Pitch Video for Cloud Connect Launch Pad

February 11, 2010 at 7:58 am In Getting Things Done, e-commerce, stuff I like, 2 Comments

VendHQ has been picked as one of 8 semifinalist for the Cloud Connect Launch Pad, and we plan on getting it to the finals.  VendHQ is one of my projects I am chipping away at.  I write the code, design the screens, develop the strategy, put together the demo videos and make the coffee.

Check out the video and VOTE for VendHQ using this link http://launchpad.cloudconnectevent.com/vote-now/ and help a kiwi company get to the finals.

Yes I do the voice overs too ;)

Tourism Futures 2050

February 3, 2010 at 9:11 am In Rants, Tourism, Web, Work, No Comments

I was privileged to be invited along to participate on the NZ Tourism 2050 Future Maker project and workshop to discuss themes and issues that NZ will face in the next 40 years. I was in the unfortunate position to be a technologist trying to predict trends 40 years out. Lucky me. I pick… tele-porters… and Mars tourism? 40 years is an eternity.  I don’t think 40 years ago my parents thought their grandchildren would be tweeting and FaceBooking from things called iPhones.

Interestingly there were two strong themes that came up time and time again in the discussions. They were quite different but I saw them to be critically intertwined.

The first issue is the broad one of technology, and everything got lumped in together in this one from the social web, mobile payments, augmented reality, connectivity and mobile information tools. The one thing everyone agreed is that technology is changing the way people interact and make decisions when they travel. Interestingly one of the greatest fears/opportunities was the power of social networks, social communication and viral ideas. I say this is both a fear and an opportunity as clearly the affect can be either positive or negative.

The other top issue was on of our image as 100% pure, clean and green and preserving this and leveraging more off our natural beauty in a world where the environment is going to hell in a handbasket.

Why are these intertwined? Well once upon a time you used the glossiest of brochure with the most stunning of photos promising the best experiences in all your tourism marketing, and then hoped, when the traveller arrives, to deliver on the experience. Today there is a fear of social media within tourism, and I don’t expect this is limited to NZ tourism operators. What if we say we are 100% pure and the world discovers we are not quite 100%, perhaps only 85%, but worse, tweets, blogs and tells all their friends and followers.  What if someone has a bad time? What if the next viral thing is a video of a bad experience or image that breaks the illusion of our 100% clean and green image. This image is our marketing capital.

The reality is with more and more people using their social web connections as their primary source of information, this image could be damaged if we as a whole can not live up to what we are promising. Driven from the Auckland Airport into the city before? Been discussing high intensity beef farming lately? Shipped any coal to china lately? Okay you cant expect everything to be 100% squeaky clean and I don’t think that our 100% pure image is so misleading that an angry internet mob will develop and something viral will spread tarnishing our image and turning the world off of visiting our shores. Of course New Zealand is a beautiful and amazing place. Some of our less cellubrious “scenes” are so so. But today is there is a risk of painting a perfect image to sells plane tickets and beds, and have people picking on all the bad images around NZ that are in direct contrast and have this influence the way they talk about and describe New Zealand socially? Like I say if expectations are consistently not met, there will be negative comments and these will turn off others.  Nothing has changed here, it is the age old power of word of mouth, it is just that technology allows people to share this information more readily.

So forgetting the 100% pure image for now, this marketing campaign has worked well for us for so long but it may be up for an overhaul soon. The pervasiveness of technology in our lives today and the ability for people to enable others to vicariously share their experiences means that whatever our strategy is, we have to be somewhat genuine in how we promote anything online, whether it is NZ as a whole, a bed and breakfast, or a scenic walk. But don’t fear being caught out for not living up to expectations (I think it is in our national psyche to underrate ourselves) but even better than that focus on making sure the traveller gets the best experience they can possibly have and then enable them to use the social web to do all the good marketing for you. You can’t control what people say, but you sure can positively influence it.

So one asset we have got is our natural beauty. Another asset is our people. Nobody is more passionate about New Zealand than New Zealanders. What if we connected travellers to New Zealand with kiwis online? What if we got kiwis to describe places in blog posts. Share trip ideas “If you are coming to Auckland then you NEED to do …”.  Share their own views, photos or videos of their New Zealand.  This would create an opportunity for travellers to see NZ through our eyes before they come.

What if tourism operators participated in FourSquare, new checkins today get a complimentary coffee with breakfast, 10% off a bungee. What if we really engaged as a country with visitors online socially? No not just a FaceBook page, something smarter and engaging. Travel is all about seeing new things and meeting new people, and sharing the experience with others. We can make it easier for visitors to connect both with New Zealanders and their own friends back home.

We need to find ways to enable all the organizations tasked with promoting New Zealand as a whole, or particular districts, to engage with travelers online and encourage them to share their experiences while they are here and still on the buzz of jumping off a bridge with a bungee around their ankles. Let them tell the world NZ is 100% cool, 100% awesome, 100% the best country they have ever visited, in their own words. Enable people to have genuine positive conversations.  The technology is there so what’s the hold up?

The first barrier, as I talk about above, is the willingness of the tourism industry to engage, but I think we can overcome that.  There is a second major barrier.   We need to find ways to let tourists connect online while they travel without crippling data roaming costs or oppressive WIFI fees. Right now tourists don’t often tweet, and post up photos on the go while they are actually feeling the buzz because to do so would make them broke. Free or cheap ubiquitous WIFI is unheard of. We need to make it easier for travellers to remain connected while they are here.

Here are some ideas:

  • Telecom/Vodafone partner with Tourism NZ to offer tourist SIMs with prepaid data and calls. Sure you can do this now but it is not at the front of a travellers mind to have to go out of their way to source a prepaid SIM for their phone. These should be on sale at the airport and at the reception of their accommodation packaged up in deals specially for tourists. It should be cheap and accessible.
  • A partnership with a national WIFI network. What if Tomizone was packaged up to tourists and gave the traveller special online discounts for accommodation and activities only available through the Tomizone network?  There is benefit for all there.
  • The i-SITEs. What is their future? Well one thing to make them more valid is to offer free WIFI for travellers. Perhaps even serve drinks and evolve into a travellers meeting place.
  • At the very least accommodation providers need to offer their WIFI for free.

I think the fear of bad exposure through social media is not 100% justified. NZ really is a great destination (not that I am biased or anything) and for the most part I am sure everyone has an awesome time. The real fear, I believe, is that we are not able to capitalize off of the power of the social web. If we fear that people will say bad things to their friends then will will only discover that yes some people say bad things.  But what if we could facilitate travellers to share all their great comments and experiences?  One thing is for sure, a country our size and with our marketing budget, we need to maximize any opportunity the Internet and technology provides.  Pioneering an integrated approach of new technology and social media into our national tourism strategy may not be a bad start.

First review of the iTablet/iSlate

January 27, 2010 at 6:57 am In Uncategorized, No Comments

OK, so I haven’t posted for ages, I’ve been busy! But excitingly I have just been contacted by my close personal friend Walt Mossberg and he shared with me the first review of the iSlate/iTablet/iThingamegiggy.  Wow, enjoy!  I for one am looking forward to the unicorn arriving through my door with my favorite pizza.

One for Movember(tm) again

November 6, 2009 at 12:59 pm In Uncategorized, No Comments

I seem to be getting a few hits today from people obviously looking for this post from last year. It must be Movember… :})

I can summon things with my mustache!

http://www.philintheblanks.com/comics/manenough.html

Is augmented reality really a reality – Barcamp Auckland notes

July 12, 2009 at 11:07 am In stuff I like, No Comments

Yesterday I did a brief presentation on augmented reality (AR) at Barcamp Auckland. Having no internet connection, and no mini DVI connector for a VGA projector, I kinda had to roll with it and talked more and showed less visuals apart from a few vids. Here are some notes from my original presentation and some links to videos for more info.

As you can appreciate this is a big topic, but I just wanted to touch on the basics for the 30 minute talk. I am no expert in AR but I think there is a huge opportunity for businesses or individuals to enter this space today and be at the top of the curve.

Augmented reality is part way along the spectrum towards virtual reality. VR is where you experience a fully digital or synthesised environment, whereas AR is where you take a real environment and overlay digital data and imagery to enhance the scene. The most typical example of this is the heads up display in a fighter jet. Airspeed, altitude, pitch, and bad guys are all highlighted in the line of view of the pilot.

There are three most common types of AR that I will cover:

  • Projection AR
  • Windowed AR
  • Retinal display

Projection AR

Picture 67This is where you utilise a camera and projector to interact with your environment. The camera to observe, and the projector to display overlay information.

This type or AR is currently in use in vehicles to project driving information and directions onto the windscreen so it appears in the line of view of the driver.

See this video of the BMW HUD (mind the music).

Here is a fantastic presentation by the MIT team about their wearable AR projector

This style of AR is good for interactions with environments where you have canvases that are close to you. This would not work obviously when wanting to interact with a mountain, a building across the road and so on.

Retinal Projection

Picture 69This is where using some eye-wear, with built in camera and micro projection device, projects additional information augmenting the scene directly onto the retina. Think of this as your own personal HUD, that can give you directions as you walk, alert you to new messages, identifying objects and providing detailed information about them.

The best example of this is as seen in the movie Terminator.

Windowed AR – What you can do today

Picture 68This style of AR is where you use a intermediary device as your window onto a real scene. Think of it as a looking glass. This could be a mobile phone, or portable video device. The device views the scene as you would, and renders it on a screen. It can then overlay digital information on top.

This is the most exciting form of AR for me at the moment as this is relatively easy to achieve using the latest styles of mobile phones, like the iPhone 3GS, Android G1 and G2. Here is what you need to achieve basic AR information overlays on a mobile phone.

Video

You will need a decent video camera within in the device to view and a screen to render the scene.

GPS

The phone needs to know WHERE it is. Consumer GPS can get fairly accurate within a 10 meter area.

Picture 64

Compass

A digital compass to determine which way the phone is pointing.

Picture 59

Accelerometer

What angle is the phone looking at. Is it looking down, up, slightly on an angle?

Picture 65

Combining these things together you get a pretty accurate position as to what the device is looking at. The accuracy has quite some variance, so this works quite well when dealing with large outdoor scenes where the objects are large, for example a tourism application where you might be walking through downtown Auckland or Rome and looking at landmarks, or for real estate where you are covering a suburb and providing property information from the roadside.

Image recognition

A powerful extension to AR is the inclusion of image and shape recognition. By adding this to position, direction and angle, you enable the device to recognise “things” in the scene. These could be features of the landscape, peoples faces, buildings, or objects in a room. This increases the accuracy of AR considerably, but adds complexity by needing to develop algorithms to process realtime video and identify objects. Currently mobile devices are a little underpowered to allow for this but there are some exciting developments underway, and on the next generation devices this will be even more of a reality.

The most common example of image recog today are where a printed patteren or fiduciary marker is used to let the device identify a canvas in the scene. The device then overlays onto or replaces the marker with some digital information. There are examples of this where a 3D object is superimposed onto the scene and the perspective of the object matches the angle and direction viewed by the devices.

This example is a virtual pet for the iPhone

This is a concept game by NVidia using their new GPU chip-set for mobile devices.

Killer Apps

Tourism – A virtual guide, that can identify when you are near a point of interest and provide visual and or audio information about it. A point and identify tool, to get information of landmarks.

Real Estate – Roadside guide to property that guides you from house to house, and provides detailed information from the curb.

Engineering – An app to allow field engineers to easily find buried cables, pipes, or even just a power meter.

What else?? The exciting thing is there are hundreds or applications yet to be discovered.

More Links

FaLLen SREngine demo http://www.youtube.com/watch?v=LhujKGuhiK0

Wiki article on Virtual retinal display http://en.wikipedia.org/wiki/Virtual_retinal_display

BMW Augmented reality for engineering http://www.youtube.com/watch?v=P9KPJlA5yds

A good wiki article on AR http://en.wikipedia.org/wiki/Augmented_reality

If you want to start developing here is a handy development toolkit – http://www.hitl.washington.edu/artoolkit/

Rhys Darby, only 2 degrees of separation you know

July 5, 2009 at 6:45 pm In Getting Things Done, Web, stuff I like, 3 Comments

Today’s interconnected world has torn down the barriers and now you can be 2 degrees of separation from the Queen (supposedly) and through social networks this certainly true, follow @rhysiedarby for example. Rhys even plugged my charity bike ride (but then we were mates so that’s like 1 degree of separation).

So we have a new mobile network launching, and who would you rather watch on the ads, Richard Hammond, or our very own Rhys? I know who is funnier.

Now, all 2degrees needs to do now is secure the domain name 2degrees.co.nz and their launch would go much more swimmingly. I do enjoy a drop of pinot now and then so no rush there guys ;)

How I cycled across the straits

July 5, 2009 at 5:29 pm In distractions, stuff I like, 2 Comments

I keep getting asked, how hard was it cycling across Cook Strait on my south to north cycle of NZ. Well to all you smart arses, THIS is how I did it so shut up. Well actually I didn’t have one of these puppies but, damn, I wish I had one. They look like fun.

Starting with a clean plate

June 9, 2009 at 2:59 pm In Getting Things Done, Life, No Comments

Well I have just cycled the length of New Zealand. Cool! Now what?

I did the cycle to prove a point, that nothing is impossible. Somethings are improbable but there is a big difference between improbable and impossible. I never thought I would be able to do something like ride a bike from one end of the country to the other, very improbable. So I broke it down, figured out what I needed to do, I came up with a plan and I did it. I took the improbable, removed as much of the risk and uncertainties as possible and boiled it down to a bunch of smaller things I could achieve:

  • Ride a bike? check.
  • Ride a bike up a hill (without vomiting)? check.
  • Ride a bike for a whole day? check.
  • Ride a bike for a day then be able to get up the next day and do it again? check.

That was it. I found a replicable formula and then kept doing it until I got to the end. It is often too easy to put up barriers in front of goals, some fickle and no more substantial than a sheet of rice paper, and for you to use these as excuses as to why you can not achieve your goals. Along the way I lost 20kg, met a heap of interesting people, and had plenty of time to just think, something we all deprive ourselves of in our busy lives. The trip was a journey of discovery for myself, and I learnt a lot. Okay, I will get off of my horse now.

So, now that adventure is complete, I have this bubbling enthusiasm running through my veins and I now found myself at the next start line ready for the next adventure, which is pretty exciting. No I am not looking to roller-skate around the Antarctic, or pogo Route 66. As a part of preparing myself for the ride, I cleared all of my commitments from my plate, and now I have one of those rare and exhilarating opportunities in front of me. The opportunity to load my plate up as high as I like with new and exciting things.

So if you have any ideas, or you think I might be able to help you out with something let me know. There are some brief details on my background here. If you know me you will know I also posses boundless enthusiasm and optimism, something I am not afraid of offering about myself. I can’t offer my time free, I have bills to pay. But get in touch I would love to hear from you, before my plate fills up again.

Sneak peak on the Telecom XT network… from the fringes

May 28, 2009 at 8:33 pm In Getting Things Done, Web, stuff I like, 3 Comments

As you may or may not know I have currently put most of my digital work live on hold and am cycling up the country on a bicycle, tweeting, blogging and posting video as I go all over on http://www.nzuphill.co.nz.

Well, the other day I was given a new SIM card for the new Telecom XT network, which I quickly poked into my iPhone. And so I have come out of temporary hiatus on 8degrees.co.nz to let you know what I found. After a quick change to the APN setting on my iPhone I was away, calling and surfing on the new XT network, and THIS is what I found:

  1. Coverage
  2. 3G speeds
  3. and all from the fringes of civilisation

I must confess I felt like a kid in a candy shop, as I rode my bike from small town to small town with a permanent 3G signal and pretty decent speeds. The speeds I have been getting are obviously not fast compared to a fixed line DSL, so don’t be expecting any crazy crazy speeds just yet, but considering I can do 3G things at good 3G speeds from places like Leigh and Mangawhai, well this is a new experience for me. And if I can get 3G from further up the line as I go, I must say, with only a little hesitation, I would be very very tempted to switch from my 15 year relationship with Vodafone (BellSouth pre Vodafone) and move to Telecom New Zealand if it allows me to make full use of the iPhone that Vodafone sold me, while sitting in my local Kerikeri cafe, where to date even a basic data connection on Vodafone is a rare thing depending on where you stand on the main street and if the sky is overcast.

So Vodafone will bump things up on their own network soon. Well they sure as hell have to, as within minutes I quickly moved (albeit temporally for the moment) onto what so far seems to be a faster broader network and I kept my phone. If I can have number portability to boot, then what’s to stop me? (apart from slightly more expensive data plans). I felt a little hurt that Vodafone let another network provide better toys first. What about all the 10′s of thousands of dollars I have sent their way over the years? Couldn’t some of it gone towards a better network before Telecom got their act together?

What confuses me is why didn’t Vodafone upgrade their network pre XT launch? I have heard from quite a few previously loyal Vodafone customers already saying they are very very tempted to move networks if all Telecom say is true. Well so far I am finding it to be very true, a dramatic improvement on the connections I have been getting on the Vodafone network. Sure it is not all about data speeds and coverage, there is all the other services that you should probably compare to be 100% apples with apples, but to be honest, my needs are pretty simple. I want fast data wherever I go. I don’t care much for voice mail, or the online interface I use to access my bill. I pay every month for fast data and good great coverage, because without those things I cant access my bill online and I can’t check my voice mail from anywhere I might be around our beautiful country.

So it is still early days yet. As I continue my mad mad cycle up the country I will be comparing coverage and data speeds as I go from my bike, from the tops of hills and down in the valleys. At the beach and in the middle of the towns that until now seem to have been forsaken by GSM networks. And if I decide I’m not going to stop at the lighthouse in Cape Reinga, well at least I have the option as a potential Telecom customer to roam to another foreign GSM network with my phone and continue my ride. Perhaps cycling from one side of Europe to the other… hmmm…

Next Page »

Powered by WordPress with Pool theme design by Borja Fernandez.
Entries and comments feeds. Valid XHTML and CSS. ^Top^