HTML Applications(.htas) and Cross Domain Scripting...

Hello,

I am trying to debug one of my HTML Applications that stopped working all of the sudden. Let me tell you the problem. Features in my application depend on cross domain scripting. For those of you that don't know, an example of cross domain scripting is when you access data from another domain using javascript, the DOM and probably an IFRAME or FRAMESET. Well, my application used to work and now it doesn't. The example that I will provide below uses the same technique that I used in my application and I swear it worked before I upgraded from IE 5 to 6!

Copy the code below to an .hta file and execute it. The application asks for an URL. Type in your favorite URL and click the 'go' button. Then, using the left button of the mouse, select some text from the web page and click the 'Get Text' button. The application is suppose to alert you with the text that you selected from the web page. This example used to work, and I desperately need a workaround!

The HTA File:

<html>
<head>
<TITLE>HTML Application Example</TITLE>
<HTA:APPLICATION ID="HTAEx"
APPLICATIONNAME="HTAEx"
ICON="e.ico"
WINDOWSTATE="normal">
</head>
<body>
<span id=AddressBar style="overflow: none">
<span id=AddText>Address</span>
<input type=text value='' id=TheAddress style="width: expression(document.body.clientWidth - AddText.offsetWidth - AddGo.offsetWidth - 45)">
<input type=button value="Go" id=AddGo onclick="navigate()">
<br><input type="button" value="Get Text" onClick="getText()"><br><span><br>
<iframe src="" id="TheFrame" style="width: 100%; height: 85%"></iframe>
<script language=JScript>
function navigate()
{
document.all.TheFrame.src = TheAddress.value;
}
function clickShortcut()
{
if (window.event.keyCode == 13)
{
navigate()
}
}
TheAddress.onkeypress = clickShortcut;
function getText()
{
var doc = window.frames.TheFrame.document;
var text1 = doc.selection.createRange().htmlText;
alert(text1);
}
</script>
</body>
</html>

Sincerely,

aspmonger



Answer this question

HTML Applications(.htas) and Cross Domain Scripting...

  • Dietz

    You will need to include the 'Application' attribute in the IFRAME tag. As of IE 6 you must specify all FRAMES and IFRAMES that you wish to have laxed security permissions for by setting the Application attribute to 'yes'.

    Example:

    <IFRAME src='http://www.microsoft.com' application='yes' />



  • SnowJim

    Can't someone help me with this problem. Anyone who wants to be able to use cross domain scripting within their .hta(html applications) should be worried about this issue. Help please!
  • Terrence Chan

    Hello,

    I did lookup the HTA documentation on msdn and read about the section regarding security and 'application=yes'. I already tried that before adding this thread. I altered the script below to make it as simple as possible. Display a website, select some html text and alert it. It just doesn't work. I am trying to remain confident that this has nothing to do with DHTML becoming too powerful. Let me know what you think. Oh yeah, and try the code below for yourself.

    Updated code example:

    <html>
    <head>
    <TITLE>HTML Application Example</TITLE>
    <HTA:APPLICATION ID="HTAEx"
    APPLICATIONNAME="HTAEx"
    ICON="e.ico"
    WINDOWSTATE="normal">
    </head>
    <body>
    <input type="button" value="Get Text" onClick="getText()"><br><span><br>
    <iframe application="yes" src=http://msdn.microsoft.com id="TheFrame" style="width: 100%; height: 85%"></iframe>
    <script language=JScript>
    function getText()
    {
    var doc = window.frames.TheFrame.document;
    var text1 = doc.selection.createRange().htmlText;
    alert(text1);
    }
    </script>
    </body>
    </html>


  • HTML Applications(.htas) and Cross Domain Scripting...