Solved

Load external website with different user agent string

Posted on 2014-03-11
5
1,598 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 49

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
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.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

623 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