簡體   English   中英

抓取頁面URL並在提交表單時提交?

[英]Grabbing the page URL and submitting it when form is submitted?

我正在嘗試創建一個表單,該表單將在按下項目頁面上的按鈕以接收報價時出現。 由於項目很多,我想知道收到表單的頁面的URL,但不確定如何實現。

我的問題是如何獲取按下按鈕的頁面的URL,然后將其與表單一起作為隱藏值提交,以便我知道請求報價的項目是什么? 這是我的表格代碼。 源URL輸入只是一個占位符。

<form action="http://et-signup.topright.com/oemSignup/subscribe" name="subscribeForm" method="post" onsubmit="alert('Thank You We Will Contact You Shortly'); return true;">
<input type="hidden" name="urlOfSubscribeThankYouPage" value="http://myurl.com">
<input type="hidden" name="urlOfErrorPage" value="http://myurl.com">
<input type="hidden" name="urlOfUnsubscribeThankYouPage" value="http://myurl.com">
<input type="hidden" name="mid" value="6286675">
<input type="hidden" name="listName" value="Item Page List - 52083">
Email Address: <input type="email" required="required" name="emailAddress"/> <br/>
        First Name: <input name="profile.First Name"><br/>
        Last Name: <input name="profile.Last Name"><br/>
        Company Name: <input name="profile.Company Name"><br/>
        Phone: <input name="profile.Phone"><br/>
        Estimated Quantity: <input name="profile.Estimated Quantity"><br/>
        Comments: <input name="profile.Comments"><br/>
        Small: <input name="profile.Small"><br/>
        Medium: <input name="profile.Medium"><br/>
        Large: <input name="profile.Large"><br/>
        Extra Large: <input name="profile.Extra Large"><br/>
        2XL: <input name="profile.2XL"><br/>
        3XL: <input name="profile.3XL"><br/>
        Source URL: <input name="profile.Source URL"><br/>
    <input type="hidden" name="SubAction" value="sub_add_update">
    <input type="submit" value="Join">
</form>

您必須在尋找引薦來源網址變量。

如果您使用的是純HTML和javascript,則可以使用以下方法找到它:

document.referrer;

在PHP中:

$_SERVER['HTTP_REFERER']

在ASP.NET中:

Request.UrlReferrer

希望能有所幫助。

我為這類“元”選項所做的就是像這樣創建一個隱藏的input字段。

<input id="pageUrlInput" type="text" name="pageUrl" style="display: none;">

然后在准備好的文檔中填充此值

$(document).function(){
    $('#pageUrlInput').val(window.location.href);
}); 

這將使用頁面url( window.location.href )填充隱藏輸入字段的值。 然后在服務器上處理表單時只獲取pageUrl參數

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM