[英]how to execute javascript of one page on click in another page
The thing is I have a page A.aspx there is script in that which will create a tab. 问题是我有一个页面A.aspx,其中有一个脚本将创建一个选项卡。 from A I'm opening another page B.aspx .
从A我打开另一个页面B.aspx。
What I want is when I click a button in B.aspx . 我想要的是单击B.aspx中的按钮时。 The script in A.aspx should execute .
A.aspx中的脚本应执行。 or else the link in A.aspx which call that script should execute ..
否则A.aspx中调用该脚本的链接应执行..
you should not do this. 你不应该这样做。 It is insecure.
这是不安全的。
I am not sure whether this is the solution for your question. 我不确定这是否是您的问题的解决方案。 You can issue a Server.Transfer to Page A from Page B and pass a context variable also.
您可以从页面B发出Server.Transfer到页面A,还可以传递上下文变量。 Check this context variable and then in the Page_Load event you can call the javascript function by using
检查此上下文变量,然后在Page_Load事件中,您可以通过使用来调用javascript函数
ClientScript.RegisterClientScriptBlock method ClientScript.RegisterClientScriptBlock方法
if the calling window opened the called window just use the handle returned from the window.open. 如果调用窗口已打开,则仅使用window.open返回的句柄。 otherwise no dice.
否则没有骰子。
First, you need a link to open the new window with a call to the window.open()
function, passing it a URL and a target. 首先,您需要一个链接来打开新窗口,并调用
window.open()
函数,并向其传递一个URL和一个目标。 Pass it '_blank'
to inform the browser to use a new window: 将其传递给
'_blank'
以通知浏览器使用新窗口:
Add this link within A.aspx : 在A.aspx中添加此链接:
<a href="#" onclick="window.open('B.html', '_blank'); return false;">
New window
</a>
Second, you'll also need a reference to the new window's opener
, which is the window which created the new window: 其次,您还需要引用新窗口的
opener
,即创建新窗口的窗口:
Add this code within B.aspx (please replace FUNCTION_NAME()
with your function identifier) to call your parent window's function: 在B.aspx中添加以下代码(请用函数标识符替换
FUNCTION_NAME()
)以调用父窗口的函数:
<script type="text/javascript">
window.opener.FUNCTION_NAME(); // Call FUNCTION_NAME() within A.aspx.
</script>
You can also access window.opener.document
to access the original window's DOM. 您还可以访问
window.opener.document
以访问原始窗口的DOM。
More information is available here: 更多信息请点击这里:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.