简体   繁体   English

如何在另一页上单击时执行一页的javascript

[英]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: 更多信息请点击这里:

Documentation for window.open() function window.open()函数的文档

DOcumentation for window.opener object window.opener对象的文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何执行在另一页中写在一页中的JavaScript? - How to execute JavaScript writen in one page from another page? 如何在另一个页面上执行javascript? - how to execute javascript on another page? 如何将值从一个页面javascript传递到另一页面javascript - how to pass the value one page javascript to another page javascript 在javascript中将点击事件从一个页面转移到另一个页面 - transfer click event from one page to another in javascript 在页面加载时执行JavaScript,但在单击按钮时不执行 - Execute javascript on page load but not on button click 如何使用 JavaScript 等待单击一个页面,然后将存储在带有对象的数组中的数据显示在另一页上 - how can I use JavaScript to wait for a click on one page then take data stored in an array with objects to display it's content on another page 如何将JavaScript对象从一页发送到另一页? - How to send javascript object from one page to another page? 如何从一个页面获取JavaScript并在另一页面的php中使用它 - How to take javascript from one page and use it in php on another page 如何使用javascript从一个页面到另一个页面的go? - How to go from one page to another page using javascript? 如何使用JavaScript从另一个页面更改一个页面的CSS - How to change CSS of one page from another page using JavaScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM