File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Non-mobile device to appear as mobile device to a remote webpage Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Non-mobile device to appear as mobile device to a remote webpage" Watch "Non-mobile device to appear as mobile device to a remote webpage" New topic
Author

Non-mobile device to appear as mobile device to a remote webpage

Dave Anderson
Greenhorn

Joined: Nov 09, 2009
Posts: 29
Suppose a webpage request is made made to a website, and that the called webpage can recognize if the request is from a mobile device.

Now suppose I have a javascript program that is NOT designed to run on a mobile device, but would like to call this website and request this webpage appearing as though it were a mobile device.

Right now if I just use location.href = url, I can retrieve the non-mobile webpage ok, but not the mobile page I want.

Does anyone know how to make a webpage request and set a flag or something else to make the webserver return the page designed for mobile devices?


Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41863
    
  63
The web site most likely looks at the HTTP User-Agent header. You can play around with that using the Develop -> User Agent menu in Safari, or any number of Firefox extensions.


Ping & DNS - my free Android networking tools app
Dave Anderson
Greenhorn

Joined: Nov 09, 2009
Posts: 29
Yes, I am sure that if one can affect the User-Agent header then one can do this, since this is how webpages determine if a mobile device is calling.

I was hoping for something specific to Javascript to do this using 'location.href = url', but I assume this is a deadend from what you are saying.

Perhaps there is a way to do this using the XMLHttpRequest object.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
JavaScript can not change the headers for user agent.

Spoof it with a plug-in as Bear suggested. There are plenty of them out there.

Eric
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41863
    
  63
Err... umm... Hi Eric!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Non-mobile device to appear as mobile device to a remote webpage