Javascript或jquery:您可以加载页面然后调用一个函数吗? [英] Javascript or jquery: Can you load a page and then call a function?

查看:75
本文介绍了Javascript或jquery:您可以加载页面然后调用一个函数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景::您有一个脚本,用户可以将其放置在他们的网站上,当他们单击该脚本时,它会重定向到我的网站,然后仅在成功重定向到我的网站后才调用函数,并且该功能是我网站的一部分,因此使用相同的来源安全策略应该不会有任何问题.

Scenario: You have a script that users can place on their website and when they click on it, it redirects to my website then calls a function only after they have successfully been redirected to my website and the function is part of my website, so there shouldn't be any problem with the same origin security policy.

那么这种情况可能吗?

编辑

好吧,现在我知道可以做到了,我遇到了一个泡菜.

Ok now that I know that it can be done, I run into a pickle doing this.

function main(){
$(document).ready(function($){
window.location.href = 'http://www.example.com/michael';
theclient.chat();

});
} 

我希望在加载example.com/michael之后调用client.chat(),但它不起作用.

I want theclient.chat() to be called after example.com/michael is loaded but it's not working.

更新2

function main(){
window.location.href = 'http://www.reflap.com/michaelnana';

$(document).ready(function(){
theclient.chat();

});

}

这行得通吗?

推荐答案

您必须在以下代码段中在自己的站点上调用该函数:

You have to call that function on your own site in the following block:

源页面:

function main(){
    window.location.href = 'http://www.example.com/michael';
}

目标页面(http://www.example.com/michael):

$(document).ready(function(){
    theclient.chat();
});   

请注意:如果您也键入页面的URL(不仅是在重定向之后),就会调用此名称.

To be clear: this will be called, if you type the URL of the page too and not only after a redirect.

如果只想在重定向后调用它,则在执行重定向时应添加URL参数.

You should add a URL parameter when you do the redirect, if you want to call it only after a redirect.

更新: 重定向完成后,您将无法在原始页面上调用函数.

UPDATE: You cannot call a function on the original page, after the redirect has been done.

这篇关于Javascript或jquery:您可以加载页面然后调用一个函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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