我可以将 Action URL 封装在 document.forms[0].action="" 中吗使用 pageTracker._getLinkerUrl?

发布于 2024-12-21 09:42:49 字数 847 浏览 0 评论 0 原文

我有一个不调用操作的网络表单,但在提交时会发送到 Javascript 函数,该函数本质上将信息推送到第 3 方预订引擎,并且我想传递 cookie。基本上,表单被发送到:

<a href="javascript:sendToCBE();"><img src="#"></a>

sendToCBE 函数如下:

function sendToCBE(){
if (validateForm()){
    setHidden();
    document.forms[0].target="_blank";
    document.forms[0].action="http://partners.kcdataservices.com/resort/custom/buildMyOwn.jsp";
    document.forms[0].submit();

是否可以将其更改为

function sendToCBE(){
if (validateForm()){
    setHidden();
    document.forms[0].target="_blank";
    document.forms[0].action="pageTracker._getLinkerUrl(http://partners.kcdataservices.com/resort/custom/buildMyOwn.jsp)";
    document.forms[0].submit(); 

为了进行跨域跟踪并传递 cookie,以便第 3 方预订引擎不会设置新的 cookie?有没有我还没有找到的更好(或更简单)的方法来做到这一点?

I have a web form that does not call an action, but when submitted gets sent to a Javascript function, which in essence, pushes the information to a 3rd party booking engine, and I want to pass the cookies along. Basically the form gets sent to:

<a href="javascript:sendToCBE();"><img src="#"></a>

The sendToCBE function is as follows:

function sendToCBE(){
if (validateForm()){
    setHidden();
    document.forms[0].target="_blank";
    document.forms[0].action="http://partners.kcdataservices.com/resort/custom/buildMyOwn.jsp";
    document.forms[0].submit();

Is it possible to change this to

function sendToCBE(){
if (validateForm()){
    setHidden();
    document.forms[0].target="_blank";
    document.forms[0].action="pageTracker._getLinkerUrl(http://partners.kcdataservices.com/resort/custom/buildMyOwn.jsp)";
    document.forms[0].submit(); 

In order to have cross domain tracking and pass along the cookies so new ones are not set by the 3rd party booking engine? Is there a better (or simpler) way to do this that I have not found yet?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晚风撩人 2024-12-28 09:42:49

您可以尝试一下这个片段。确保将 GA 相关代码放入 try catch 中,这样即使网站上未设置该代码,表单仍然可以工作。

function sendToCBE(){
  var action = "http://partners.kcdataservices.com/resort/custom/buildMyOwn.jsp";
  try{
    var tracker = _gat._getTrackers()[0];
    action = tracker._getLinkerUrl(action);
  }catch(e){
    // _gat doesnt exist or there is no tracker setup. Just ignore it and continue
  }
  if (validateForm()){
    setHidden();
    document.forms[0].target = "_blank";
    document.forms[0].action = action;
    document.forms[0].submit(); 
  }
}

You may try this snippet. Make sure to put GA related code inside a try catch so if it's not setup on the site the form still works.

function sendToCBE(){
  var action = "http://partners.kcdataservices.com/resort/custom/buildMyOwn.jsp";
  try{
    var tracker = _gat._getTrackers()[0];
    action = tracker._getLinkerUrl(action);
  }catch(e){
    // _gat doesnt exist or there is no tracker setup. Just ignore it and continue
  }
  if (validateForm()){
    setHidden();
    document.forms[0].target = "_blank";
    document.forms[0].action = action;
    document.forms[0].submit(); 
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文