在iframe中运行Javascript [英] running Javascript inside a iframe

查看:95
本文介绍了在iframe中运行Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用asp.net iframes开发一个非常小的系统.我开发了一个页面,说search.aspx,并在其中使用iframe来显示Google,yahoo,Cuil,Bing等按钮点击,就像这样的代码

I am trying to develop a very small system using asp.net iframes.i have developed a page saying search.aspx and have used iframes in this to show Google, yahoo, Cuil, Bing etc on button click like this code

<pre lang="xml"><html>
<head>
<meta http-equiv="Content-Language" content="en-gb">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<link href="searchstyle.css" rel="stylesheet" type="text/css" />
<title>Search Domain</title>
<meta name="description" content="">
</head>
<body>
<div align="center" style="font-size: x-small; font-family: arial, helvetica, sans-serif">
<form name="jumpy">
<select name="example" size="1" onChange="gone()">
<option value="http://www.yahoo.com" selected>Yahoo.com</option>
<option value="http://www.google.com">Google.com</option>
<option value="http://www.news.com">News.com</option>
<option value="http://www.altavista.com">AltaVista.com</option>
<option value="http://www.gmail.com">Gmail.com</option>
<option value="http://www.nasa.gov">Nasa.gov</option>
<option value="http://www.rediffmail.com">rediffmail.com</option>
<option value="http://www.customise.com">Customise</option>
</select>
<input type="button" name="test" value="Go!" onClick="gone()"/>
<input type="Text" name="customise" disabled="disabled" title="Enter Ur Search Url"/>
<input type="button" name="test1" value="Get!" onClick="go()" disabled="disabled"/>
</form>
<script language="javascript" type="text/javascript">
<!--
//Specify display mode (0 or 1)
//0 causes document to be displayed in an inline frame, while 1 in a new browser window
var displaymode=0
//if displaymode=0, configure inline frame attributes (ie: dimensions, intial document shown
var iframecode='<iframe id="external" style="width:100%;height:100%" src="http://www.yahoo.com"></iframe>'
/////NO NEED TO EDIT BELOW HERE////////////
if (displaymode==0)
document.write(iframecode)
function gone()
{
var selectedurl=document.jumpy.example.options[document.jumpy.example.selectedIndex].value
if( selectedurl == 'http://www.customise.com')
{
document.jumpy.example.disabled = true
document.jumpy.test.disabled = true
document.jumpy.customise.disabled = false
document.jumpy.test1.disabled = false
}
else
{
if (document.getElementById&&displaymode==0)
document.getElementById("external").src=selectedurl
else if (document.all&&displaymode==0)
document.all.external.src=selectedurl
else{
if (!window.win2||win2.closed)
win2=window.open(selectedurl)
//else if win2 already exists
else{
win2.location=selectedurl
win2.focus()
}
}
}
}

function go()
{
var selectedurl=document.jumpy.customise.value
if (document.getElementById&&displaymode==0)
document.getElementById("external").src=selectedurl
else if (document.all&&displaymode==0)
document.all.external.src=selectedurl
else{
if (!window.win2||win2.closed)
win2=window.open(selectedurl)
//else if win2 already exists
else{
win2.location=selectedurl
win2.focus()
}
}
}
//-->
</script>
</div>
</body>
</html>


<pre lang="HTML">



但是问题是我想插入这些脚本



but the problem is that i want to insert these scripts

<script type="text/javascript">
document.oncontextmenu=new Function("return false");
</script>







and

<script type="text/javascript" src="www.xyz-abc.co.in/js/..../me.js">
</script>




在iframe加载内容后,此javascript应该合并到加载内容中,并应在正在加载的页面中运行.谁能建议我.我已经使用jquery进行了检查,但没有结果.

换句话说,我希望每个人都在iframe中运行一个脚本文件,并且每次将新内容加载到iframe中.




after iframe load the contents, this javascript should merge into the loading contents and should run in the page being loaded. could any one can suggest me. i have checked it using jquery but no results.

in other words i want to run a script file inside the iframe each and evry time new contents are loaded to iframe.

推荐答案

如果您拥有要构建的页面,那么您只需将脚本包括在该页面上.
您不能也不应将您的JavaScript注入到您不拥有的页面中.考虑一下安全隐患.那太傻了.
If you own the page which you are framing, then you simply put the script include on that page.
You can''t and shouldn''t be able to inject your javascript into a page not owned by you. Think about the security implications. That would be silly.


这篇关于在iframe中运行Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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