1

I want to load an external page (i.e. google or facebook auth) into a iframe when the user clicks a button. How would you do this using MVC3 and Razor?

This seems like an extremely trivial task, but I can’t seem to figure out what to ask Google so I get something back I can use.

1 Answer 1

6

You could use JQuery something like this:

<script type="text/javascript">
    $(function () {
        $('#myButton').click(function () {
            $('#myFrame').attr('src', 'http://www.google.com/');
        });
    });
</script>
<iframe id="myFrame"></iframe>
<button id="myButton">
    Refresh IFrame
</button>

However, you will find that some sites (such as google.com) will prevent you from doing this, as they can specify in their response header whether or not the page can be opened in an IFrame. This is to prevent 'clickjacking' and is built in to most modern browsers.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.