SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Oct 2004
    Location
    PA
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Load External URL in client browser and Get Result

    I need to load an external URL in the client's browser (because the data on the external page depends on a cookie stored on the user's computer), get the data that was returned by that URL (an integer), and then interpret the data and display in a user-friendly manner via the page on my server. I assume this can be achieved somehow with javascript.

    Thanks in advance…

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,271
    Mentioned
    197 Post(s)
    Tagged
    3 Thread(s)

    js remote file

    AJAX is under the "same domain" security restriction, so you are limited. The only thing I can think of is to use a (hidden) iframe (or object) tag and use javascript to parse out what you want.
    Not the most efficient way to get an integer. Are you sure you can't use a server-side language for this?
    Also, I'm not sure that domains can get at cookies set by other domains, whether because of security limitations or browser option settings, it seems somewhat unlikely.
    If you can post more detail maybe an alternative solution can be found.

  3. #3
    SitePoint Member
    Join Date
    Oct 2004
    Location
    PA
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help, Mittineague.

    I'm working on an iPhone web-app to redeem Pepsi Stuff codes. I have a form that, when submitted, loads a pepsistuff.amazon.com url in an iframe (which I've left visible for the time being). If the code is valid and the user is logged into Amazon, the Amazon page shows the user's new balance. Otherwise, the page shows a negative number representing an error occurred. I want to interpret the number that amazon returns and display it in a user-friendly manner.

    And I've gotten it to the point where it works running in Safari 3 on my Mac, but Safari on the iPhone still reports "unsafe" javascript activity when trying to read the number from the amazon iframe.

    Simply loading the page and clicking redeem should result in either -2 or -3 in the iframe, and the "Please Wait" text should change to the corresponding error message. If "Please Wait" never changes, then we've run into cross-domain security limitations.

    I wasn't aware that cross-domain scripting was such a problem. Do you know of a way to get around the cross-domain security (specifically with MobileSafari on the iPhone) or can you think of another way to accomplish what I want? (Feel free to take a look at my sloppy code via the page source.)

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,271
    Mentioned
    197 Post(s)
    Tagged
    3 Thread(s)

    show something friendlier

    The Opera error console shows a "Resorce Error" "attempted to write protected variable" message. AFAIK, this is because the scripts are from different domains (page vs. iframe).
    Do you know of any documentation/API for the manifestElementControl.js file?

  5. #5
    SitePoint Member
    Join Date
    Oct 2004
    Location
    PA
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now that you mention it, I've eliminated manifestElementControl.js completely and wrote my own method to handle printing the result to the DIV:
    Code:
    function showResult(result)
    {
    	document.all.results.innerHTML = "<h2>"+result.toString()+"</h2>";
    	//"results" being the name of the DIV
    }
    Anyway, I think the problem arises with the following line:
    Code:
    var content = window.frames[0].document.body.innerHTML;
    In other words, as soon as I try use the data in the Amazon frame locally.

    I think I'm getting around this on Safari on my Mac simply by putting the following into my javascript:
    Code:
    document.domain="pepsistuff.amazon.com";
    It works on Safari on my Mac, just not on the iPhone.

    Is there another way to pull the data out of the Amazon frame to use locally?

  6. #6
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,271
    Mentioned
    197 Post(s)
    Tagged
    3 Thread(s)

    iphone problems

    I do not know how the iPhone implements the DOM or how it supports javascript. Is it Apple iPhone 1.1.1 ?? http://www.securityfocus.com/bid/25850

  7. #7
    SitePoint Member
    Join Date
    Oct 2004
    Location
    PA
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I personally am testing with Mobile OS X (iPhone) 1.1.3, and Safari 3.0.4 on Mac OS X 10.5.2. (All of which are the latest versions available.) Works on the Mac, not on the iPhone. There must be a hole that they fixed on the iPhone but not on the desktop version of Safari, which is strange.

    I've settled with just displaying the iframe for now. It's far from ideal, but it works. The modified version that just blindly displays the iframe, is here. From what I understand, I can't even style the text in the iframe. Oh well.

    Heh. What are the chances Amazon would cooperate with me somehow to get this to work the way that I want? I'm obviously not trying to do anything malicious here.

  8. #8
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,271
    Mentioned
    197 Post(s)
    Tagged
    3 Thread(s)

    chances

    I hope they would be ageeable. Since you only need to get an integer, it would save bandwidth.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •