Solved

Load external website with different user agent string

Posted on 2014-03-11
5
1,301 Views
Last Modified: 2014-03-16
Hi

For educational propose.
I am trying to display an external website (with a mobile user agent string ) in my website.
I have googled around, and some ppl said its achievable using
a) iframe with javascript

http://stackoverflow.com/questions/14248446/setting-useragent-of-iframe-via-javascript

<script>  
$(function () {
        var frame = $('<iframe width="320" height="480"></iframe>');
        frame.hide();

        $('#container').append(frame);
        var contentWindow = frame[0].contentWindow || frame[0].contentDocument;

        var setUA = function() {
            if (Object.defineProperty) {
                Object.defineProperty(contentWindow.navigator, 'userAgent', {
                    configurable: true,
                    get: function () {
                        return 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5';
                    }
                });
            } else if (Object.prototype.__defineGetter__) {
                contentWindow.navigator.__defineGetter__('userAgent', function () {
                    return 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5';
                });
            } else {
                alert('browser not supported');
            }
        };

        $.ajax({
            cache: false,
            url: '/index.htm',
            success: function (html) {
                contentWindow.document.open();
                setUA();
                contentWindow.document.write(html);
                contentWindow.document.close();
                frame.fadeIn();
            }
        });
    });
</script>

Open in new window


b) cURL

But i can seem to make it work.
Note: totally newbie in these
0
Comment
Question by:Shirley80
5 Comments
 
LVL 17

Expert Comment

by:Kent Dyer
ID: 39922468
Is there a purpose for this other than "education?"  What is the "value-add" of this?  What is it you are looking to do?  I am trying wrap my arms around this and cannot make sense of it.
0
 

Author Comment

by:Shirley80
ID: 39922648
It's for a file sharing website.
User won't need to login if the site is viewed in mobile browser.
thx
0
 
LVL 48

Accepted Solution

by:
dbrunton earned 300 total points
ID: 39922655
If you are using Firefox then try this addon

https://addons.mozilla.org/en-US/firefox/addon/user-agent-switcher/

Enables you to switch to different User Agents which is what I think you want for testing your website.
0
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 200 total points
ID: 39922680
Chrome Developer Tools will emulate quite a few phones including the different iPhones.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39932262
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now