Solved

Load external website with different user agent string

Posted on 2014-03-11
5
1,405 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Internal to DMZ IIS Authentication. 3 28
Add shadow behind div 5 25
how can i turn the array into an object 4 50
ASP.NET Content Page 3 35
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

821 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