简体   繁体   English

我可以建立一个链接1.离开页面浏览并执行2. Javascript吗?

[英]Can I make a link 1. navigate away from page and 2. execute Javascript?

I have a piece of javascript code that I want to execute on the page a user navigates to. 我要在用户导航到的页面上执行一段JavaScript代码。 So I have 所以我有

<a href="www.google.com">

and once he clicks it I want to execute 当他单击它后,我要执行

javascript:Alert("you're on google")

Is there anyway to do this? 反正有这样做吗?

I thought of setting up a PHP page somewhere that accepts a URL as a parameter and then wraps the js in it, but that would affect my webserver traffic and probably not work for session based websites... 我想到在某个地方设置一个PHP页面,该页面接受URL作为参数,然后将js包装在其中,但这会影响我的网络服务器流量,并且可能不适用于基于会话的网站...

You can for sure execute a script * then * navigate away . 您可以确定执行脚本 * 然后 * 离开 But if you want to execute your script on the next page, in short , it is not possible (or all browsers try their best to make it not possible). 但是, 简而言之 ,如果您想在下一页执行脚本,则不可能(或者所有浏览器都尽力使之不可能)。 This is related to cross-page security. 这与跨页面安全性有关。

<a onclick="yourscript()" href="http://www.google.com">go to google</a>

If you are thinking about cross-domain scripting, you can google for 如果您正在考虑跨域脚本编写,则可以通过Google搜索

cross domain scripting 跨域脚本

or cross domain ajax etc 跨域ajax等

Thankfully, no. 幸运的是,没有。 Or, at least, you are not supposed to be able to do that. 或者,至少,您不应该能够做到这一点。 Running your javascript on someone else's web site is a gigantic security hole. 在其他人的网站上运行您的JavaScript是一个巨大的安全漏洞。

暂无
暂无

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

相关问题 Javascript:如何创建一个函数 1. 接受一个全局变量作为参数 2. 改变该全局变量的值? - Javascript: How can I create a function that 1. accepts a global variable as a parameter 2. alters the value of that global variable? 如何在javascript创建的文本框之间创建空格2.将它们与jsp中的另一个文本框对齐 - How to make 1. space between text boxes created from javascript 2. align them with another text box from jsp 如何在锚定href中利用javascript而不浏览页面 - how to utilize javascript in the anchor href and not navigate away from the page 用户离开页面之前,带有链接的javascript样式警报 - javascript style alert with link before user navigates away from page 使用jQuery导航离开页面 - Use jQuery to navigate away from page 有什么方法可以使用jQuery或JavaScript打开我的网站上的链接(或导航到其他页面)? - Is there any way I can open a link on my site (or navigate to a different page in general) using jQuery or JavaScript? 如果我导航到其他页面,JavaScript仍会执行吗? - Does javascript still execute if I navigate to a different page? 如何在浏览器中制作“您确定要离开此页面”警告消息吗? - How to make the 'Are you sure you want to navigate away from this page' warning message in browser? 用户在JavaScript中离开之前的HTML页面后会怎样? - What happens with previous HTML page after users navigate away from it in JavaScript? 如果我离开页面并返回该页面,更改将消失-Ionic App - Changes disappear if I navigate away from page and comeback to that page - Ionic App
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM