Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

send variables via link without redirect

Status
Not open for further replies.

Ptaco

Technical User
Jan 3, 2011
3
US
Is it possible to send variables via link in javascript without altering the users window?

Kind of like a redirect without actually redirecting the user.
 
Send to where? If you want to submit values to a server without leaving the current page, you may want to look into Ajax.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
How would that work? Opening a link will move the user to the page the link is pointing to always.

You could conceivably open the link in an iframe so the user remains on the current page, but if the contents of the linked to page are on a different sever, you won't be able to interact with it.

Using Ajax's GET method may a better alternative.

You can call the page with any parameters you require in the url and have it return whatever it produces back to your JS script.

forum1600



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
How would that work? "

exactly..

I just need to send some values via a link but have it be done without the user ever clicking it.

A better way to say this.. is it possible to send variables to a URL without using a link?
 
I'm sorry, now I'm confused. What exactly is to initiate the sending to a URL then, and how is that going to reflect to the user at all if nothing was clicked?

Perhaps if you can explain what you want to accomplish rather than the method of accomplishing it we could help you out more.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
You can use hidden forms to accomplish the same thing. The links would have an onClick() that invokes a function to populate the hidden form's fields with the values you want to pass.

For example, assume you want to link to a help facility and every page sets a 'currentPage' variable. Then,

* Your help link anchor event might be: onClick='return linkHelp(currentPage);'
* the hidden form (helpForm) would have an action attribute referring to the help page, and a field named helpTopicPage
* the linkHelp() function would set helpTopicPage.value = currentPage, then do helpForm.submit();

Note that the help page can also porovide a button to "return" since it has the original page name.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top