[ic] Specify flypage using javascript or another non-database method

Mike Heins mikeh at perusion.com
Mon Apr 27 00:25:00 UTC 2015


Quoting Peter (peter at pajamian.dhs.org):
> On 04/27/2015 07:10 AM, DB wrote:
> >>> Hi all. I'm working an making IC5 site a bit more mobile friendly and so
> >>> far it's been fairly painless. Using javascript to redirect mobile
> >>> visitors to the mobile version of a page works well. But I now need a
> >>> way to make mobile visitors see a different flypage than non-mobile
> >>> visitors see.
> 
> > Thanks - I'd been using something like below but I see other ways in the
> > archives that would probably work better with your example.
> > 
> > <script type="text/javascript">
> > <!--
> > if (screen.width <= 699) {
> > ...
> > }
> > //-->
> > </script>
> 
> Using javascript is all well and good, but you do have to direct them
> after the page is loaded and then load another page as a result.  If you
> use server-side code to detect the presence of a mobile based on the
> UserAgent string then you can use Mike's code above to do it without
> needing a redirect.  I suggest using the HTTP::BrowserDetect module to
> parse the useragent string for you.  It has, among others, methods that
> tell you if it's a mobile device and whether it's a tablet, etc.

I think you can find the is_mobile tag in our repository, it is something
we use for the Strap catalog, I believe. If not, here it is:

UserTag is_mobile hasEndTag
UserTag is_mobile Routine <<EOR
use HTTP::BrowserDetect;
sub {
	if(! defined $Vend::Session->{mobile_browser}) {
		my $ua = HTTP::BrowserDetect->new($Vend::Session->{browser});
		if($ua->mobile()) {
			 $Vend::Session->{mobile_browser} = 1;
		}
		else {
			 $Vend::Session->{mobile_browser} = 0;
		}
	}

	return $Vend::Session->{mobile_browser}
		? Vend::Interpolate::pull_if(shift (@_))
		: Vend::Interpolate::pull_else(shift (@_) );
}
EOR


-- 
Mike Heins
Perusion -- Expert Interchange Consulting    http://www.perusion.com/
phone +1.765.253.4194  <mike at perusion.com>

Celebrate Diversity...
except veterans, small-business owners, practicing Catholics, gun
owners, talk-radio listeners, tea-party attendees, Texans, smokers, limited-
government proponents, pro-lifers, taxpayers, NASCAR fans, Boy Scouts,
oil-company employees, secure-border advocates, capitalists, global-
warming agnostics, Cuban refugees, school-choicers.. -- Peter Kirsanow



More information about the interchange-users mailing list