开发者

Ajax simulating a click

Can someone let me know if this is possible with Ajax. I want to load an external site onto a page and then use jQuery, jScript, php, or some method to simulate a click on the external site page that I just loaded up.

The site will not allow the traditional post / get

<script type="text/javascript" language="javascript">
//<![CDATA[
    function FriendCenterObject() {
        var fcAction = function(actionUrl, gamerTag, responseHandler) {
            responseHandler = responseHandler || function(response) {
                if (response.status != 0) {
                    DisplayMessageDialog('Error', response.view, 'Close', null, MessageLevelType.Error);
                }
                else {
                    DisplayMessageDialog('Message', response.view, 'Close', FriendCenter.RefreshContentAction);
                }
            }
            $.post(actionUrl, { 'gamerTag': gamerTag }, responseHandler);
        };
        this开发者_JS百科.AddFriend = function(gamerTag) {
            gamerTag = $.trim(gamerTag); // trim leading and trailing whitespaces
            if (gamerTag != "") {
                fcAction('/en-US/FriendCenter/SendFriendRequest', gamerTag);
            }
            return false;
        };
        this.RefreshContentAction = function(){};
    };
    var FriendCenter = new FriendCenterObject();
//]]>
</script>

and this is the link i want users to be able to click

<a href="#" onclick="FriendCenter.AddFriend('mirco')">Add to Friends List</a>

I did some more investagating and its definitely using Post method with a content type of Content-Type:application/json


I would say its very simple. Simply use $.ajax() to get the page, and then put it on the DOM (By selecting a container element and using .html() or .append() on it, adding what ajax returns. After that, select the item you wish to click (which is now in your DOM) and call .click(). If you need specific examples, give code.


Try loading the site with:

jQuery("#iframeID").src = "path/to/site";

After loading external site into iFrame, you can try:

//getting the content window html tag.
var iFrame = document.getElementById("iframeID").contentWindow;
jQuery(iFrame.body).find("#someID").click();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜