Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Load external website with different user agent string

Posted on 2014-03-11
5
Medium Priority
?
1,754 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 1200 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 84

Assisted Solution

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

Expert Comment

by:Dave Baldwin
ID: 39932262
0

Featured Post

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
This article discusses how to implement server side field validation and display customized error messages to the client.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

722 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