I want to get redirect by click on button, I use:
<inputtype="submit" onclick="location.href='first';" value="goSomewhere1"/>
<inputtype="submit" onclick="location.href='second';" value="goSomewhere2"/>
and it workf if is clicked on page http://ADDRESS but if is clicked when url is like http://ADDRESS/something it redirects to http://ADDRESS/something/first
How is it possible to get redirect just before ADDRESS but not put this value (ADDRESS) because it could change? (for this example it should get http://ADRESS/first insted of http://ADDRESS/something/first)
You want /first not first.
Without a slash, it's a relative link. With the slash, it's absolute to the base URL.
<input type="submit" onclick="location.href='/first'" value="goSomewhere1"/>
<input type="submit" onclick="location.href='/second'" value="goSomewhere2"/>
Related
I have a simple html form. When the form is submitted, the page is refreshed and the input is appended to the url.
<form>
<input name="q" type="text" />
</form>
For example, the original URL is:
file:///Users/Download/dd.html
When the form is submitted, the URL becomes
file:///Users/Download/dd.html?q=ccc
I want to add a flag to let the backend knows where the request is from. Is it possible to add a flag into the header?
If not, I want to add &global to the end of the URL, so the url becomes file:///Users/Download/dd.html?q=ccc&global I tried to set the value of the input, but it will change what displayed in the page.
I am wondering if it is possible to add a flag into header, so my backend java code can handle it. Or, add the flag to the end of the URL.
Thanks a lot!
You cant add headers with a form but you can add other params to the form with a hidden input
<input type="hidden" name="global" value="" />
If you really want to add headers you will have to use javascript and ajax.
Keep in mind that once you use params in the url a user can either refresh the page or manually add the params which may not be what you expected.
In my website I want to allow to return from 'itemY' page to 'topicX' page.
I don't want to add a get parameter:
mysite.com?ref=topicX
I'm not sure if using document.referrer is the right way.
Also 'itemX' can be reached directly from Google so it doesn't have to show the return link.
Can you add a form with a hidden field on the page. The value of the hidden form field would be the url of the location you want to return to. Then just check for the presence of this hidden form field using js?
<form id="myForm">
<input type="hidden" id="goTo" name="goTo" value="topicX" />
</form>
I would like to create a sort of login page. Which links to a href depending on the input of the user.
So i have a text input part and a login button.
Then it should go to the website depending on the text input.
Example: users fills in 1234 and clicks on the login button, then the website:
example.com/1234 opens up.
I tried but i cant get it worked.
<input type=text id='token' name="token"/>
<input type=button name=login value="login" onClick=changeQuery()/>
changeQuery(){
var input_query=document.getElementById('sq').value;
window.location="http://www.google.com/"+input_query+"myString";
}
There are many issues with your code...
HTML attribute should be in quotes (so change things like onclick=changeQuery() to onclick="changeQuery()")
Your function does not start with the keyword function
Your textbox control has an id of token... so in the example you have, there is no sq for the getElementById to find
And I'm not sure why you're adding "MyString" at the end of the URL, but that might be part of your intended code
The result should be something like this...
function changeQuery(){
var input_query = document.getElementById('token').value;
//window.location = "http://www.google.com/" + input_query + "myString";
console.log("http://www.google.com/" + input_query + "myString");
}
<input type="text" id="token" name="token"/>
<input type="button" name="login" value="login" onClick="changeQuery()"/>
(Please note, I've commented out the window.location and instead put a console.log so you can see what is produced without it actually navigating to another page)
function changeQuery() {
var input_query =
document.getElementById('token').value;
window.location = "https://www.google.com/search?
q=" + input_query;
}
Above is the correct code for what you want, but google doesn't allow some different origin to make search request.
Refused to display 'https://www.google.com/search?q=somequery' in a frame because it set 'X-Frame-Options' to 'sameorigin'.If you try to redirect some other origin it will work.
I am trying to change url of the page by using
<body onload="location.replace('new url')">
but I want this to be back to my old URL on click un checking of a check box.
so suppose i have a checkbox as follows:
<input type="checckbox" checked>
as soon i uncheck it the page should go to the old url
use window.location.href instead.
<body onload="window.location.href = 'https://google.com'">
I am begineer of Perl. I'd like to ask how to pass value to other page when clicking an anchor tag?
The part of code are:
# ...
$cq = new CGI;
$cq->param('user');
# ...
$htmlout.='<form name="mainform" method="POST" action="/scripts/yyyy.plex">';
$htmlout.='<input type="text" name="user" value="'.$user.'"/>';
$htmlout.='Link to Page A';
$htmlout.='<input type="submit" name="pageB" value="Click to Page B"/>';
# ...
print $htmlout;
I want to pass the value that user keyin can retain on every page, I try to use $cq->param('user') or pass in url but only work on Page B, any way I can get the value that user keyin after click the link to Page A?(without ajax)
note: Labels have the name "user" exist every other page.
Produce the following output from your script:
Link to Page A
If the value isn't known when you build the page, you'll need to use JavaScript (to build the URL or to submit a form).
Link to Page A