HTML应用程序(.htas)和跨域脚本... [英] HTML Applications(.htas) and Cross Domain Scripting...

查看:51
本文介绍了HTML应用程序(.htas)和跨域脚本...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我正在尝试调试一个突然停止工作的HTML应用程序。我告诉你这个问题。我的应用程序中的功能取决于跨域脚本。对于那些不知道的人,跨域脚本编写的一个例子是当你使用javascript,DOM以及可能是IFRAME或FRAMESET从另一个域访问数据时。好吧,我的应用程序曾经工作过,现在却没有。我将在下面提供的示例使用与我在我的应用程序中使用的相同的技术,并且我发誓它在从IE 5升级到6之前有效!

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!

将下面的代码复制到.hta文件并执行它。应用程序要求提供URL。输入您喜欢的网址,然后点击"开始"按钮。然后,使用鼠标左键,从网页中选择一些文本,然后单击"获取文本"按钮。该应用程序用于提醒您使用从网页中选择的文本。这个例子以前都有用,我迫切需要一个解决方法!

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!

HTA文件:

< html>
< head>
< TITLE> HTML应用示例< / TITLE>
< HTA:APPLICATION ID =" HTAEx"结果,APPLICATIONNAME = QUOT; 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 ="获取文字" onClick =" getText()">< br>< span>< br>
< iframe src ="" ID = QUOT; TheFrame" style =" width:100%;高度:85%">< / iframe>
< script language = JScript>
function navigate()
{
document.all.TheFrame.src = TheAddress.value; < br>}
函数clickShortcut()
{
if(window.event.keyCode == 13)
{
navigate()
}


.onkeypress = clickShortcut;
function getText()
{
var doc = window.frames.TheFrame.document;
var text1 = doc.selection.createRange()。htmlText;
alert (文本);结果,},点击< /脚本>结果< /体>结果< / HTML>

<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>

此致,

aspmonger

aspmonger

推荐答案

您需要在IFRAME标记中包含"Application"属性。从IE 6开始,您必须通过将Application属性设置为"yes"来指定您希望放宽安全权限的所有FRAMES和IFRAMES。

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'.

示例:

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

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

这篇关于HTML应用程序(.htas)和跨域脚本...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆