简体   繁体   English

如何通过超链接传递变量?

[英]How do I pass a variable through a hyperlink?

I would like to start off saying that I'm very new to programming. 我想开始说我对编程很新。 I am developing a site (www.example.com) that has multiple hyperlinks. 我正在开发一个有多个超链接的网站(www.example.com)。

When a user visits my site I want all the links to be defaulted to the back office of another site (www.tvcmatrix.com/mhammonds) I use. 当用户访问我的网站时,我希望所有链接都默认为我使用的另一个网站(www.tvcmatrix.com/mhammonds)的后台。 How do I set the links to redirect to the query string value based on inputted text from a form that is on my site (www.example.com)? 如何根据我网站(www.example.com)上的表单中的输入文本将链接设置为重定向到查询字符串值?

In other words, if the url reads www.example.com/?user=abelliard, how do I make all the links on the site change to "www.tvcmatrix.com/abelliard"? 换句话说,如果网址为www.example.com/?user=abelliard,如何将网站上的所有链接更改为“www.tvcmatrix.com/abelliard”? If no query string is present, then I would like for the links to be www.tvcmatrix.com/mhammonds. 如果没有查询字符串,那么我希望链接是www.tvcmatrix.com/mhammonds。

Here is a file on my site for the form called "form.asp" 这是我网站上名为“form.asp”的表单的文件

 <!DOCTYPE html> <html> <body> <form action="viral.asp" method="get" name="input" target="_self"> Your TVC Matrix Associate ID: <input type="text" name="user" /> <input type="submit" value="Submit" /> </form> </body> </html> 

Here is the "viral.asp" file in the "form.asp" file. 这是“form.asp”文件中的“viral.asp”文件。

 <%@ language="javascript"%> <!DOCTYPE html> <html> <body> <% var id = Request.QueryString("user"); Response.Write("Your URL is: www.mca.com/?user=" + id) %> </body> </html> 

Here is the last file and front end of the site called "front.asp" 这是名为“front.asp”的网站的最后一个文件和前端

I have 'viral' and 'form' down packed. 我有'病毒'和'形式'打包。 The main thing I needed help with was the front end of the site that deals with the links. 我需要帮助的主要事情是网站的前端处理链接。

I have no clue if I am even a tad bit close or way off track, but what I have isn't working at all so I know it's wrong. 我不知道我是否有点偏离或偏离轨道,但我所拥有的根本不工作,所以我知道这是错的。

 <!DOCTYPE html> <html> <head> <title>Main Site</title> </head> <body> <a href="http://www.tvcmatrix.com/" + id="function" target="_blank" name="link">Click Here!</a> <iframe width="450" height="40" src="form.asp"> </iframe> </body> <script lang="javascript" type="text/javascript"> function tvcid() { var username = document.getElementById('username'); if (username.value != "") { tvcid = "username"; } else { tvcid = "mhammonds"; } } </script> </html> 

How do I pass a variable through a hyperlink? 如何通过超链接传递变量?

For staters, you're not using a hyperlink, you're submitting a form. 对于州议员,您没有使用超链接,而是提交表格。

Request.QueryString("user"); is looking for something on the querystring. 正在寻找关于查询字符串的东西。 You're using POST, which has form fields. 你正在使用POST,它有表单字段。

Use Request("user"); 使用Request("user"); , which will grab the value regardless of whether it's on the querystring or a POST field. ,无论是在查询字符串还是POST字段,它都会获取值。 If you want to force recognition of form fields only, use Request.Form("user"); 如果您只想强制识别表单字段,请使用Request.Form("user");

Classic ASP code is executed server side when the page loads. 页面加载时,在服务器端执行经典ASP代码。 You are submitting a form inside an iframe, and the result page is also displayed inside the iframe. 您正在iframe中提交表单,结果页面也会显示在iframe中。 This result can't change anything on the parent page because it has already been loaded. 此结果无法更改父页面上的任何内容,因为它已加载。 The easiest way around this would be to have all your code on the same page. 最简单的方法是将所有代码放在同一页面上。 I'll show you how to do this with VBS as the scripting language, it's what I'm used to, but it should be easy enough to use server side JS instead 我将向您展示如何使用VBS作为脚本语言,这是我习惯的,但它应该很容易使用服务器端JS代替

<%@ language="VBScript"%>
<%
 Dim id
 If Request("user") <> "" then
 id = Request("user")
 else
 id = "mhammonds"
 End if
%>
<!DOCTYPE html>
<html>
    <head>
        <title>Main Site</title>
    </head>
        <body>
            <a href="http://www.tvcmatrix.com/<%= id %>" target="_blank" name="link">Click Here!</a><br />
        <% If Request("Submit") <> "Submit" then %>
            <form method="get">
        Your TVC Matrix Associate ID: <input type="text" name="user" />
        <input type="submit" name="submit" value="Submit" />
        </form>
        <% else 
        Response.Write("Your URL is: www.mca.com/?user=" & id)
        End If %>
    </body> 

</html>

If you really don't want to have to reload front.asp then you need to look at ajax, and add the relevant tag to your question 如果你真的不想重新加载front.asp那么你需要查看ajax,并在你的问题中添加相关的标签

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

相关问题 如何通过网址传递JavaScript变量? - How do I pass a javascript variable through a URL? 如何通过反应中的组件传递变量的值? - How do I pass the value of a variable through the components in react? 如何在不调用方法的情况下通过另一个方法传递方法,并将变量 object 传递给它? - How do I pass a method through another method without it being called, and pass a variable object into it? 如何将超链接的 URL 设置为 js 变量? - How do I set the URL of a hyperlink to a js variable? 如何通过此Java脚本函数传递字符串变量,然后将其传递给getElementById()? - How do I pass a string variable through this java script function and then into getElementById()? 如何在Ajax脚本中将变量从表单传递到php页面? - How do i pass a variable from a form through to a php page in an ajax script? Node.js:如何将全局变量传递到通过require()插入的文件中? - Node.js: how do I pass global variable into a file being inserted through require()? Vue3 - 如何在@click function 上传递变量名? - Vue3 - How do I pass through a variable name on a @click function? 如何在尚未评估的情况下将变量传递给自定义组件? - How do I pass a variable through to a custom component without having it evaluated yet? 如何在超链接中包含javascript变量? - How do you include a javascript variable in a hyperlink?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM