I want to redirect users to the previous page whenever they visit a specific page
Let's say: page123.php
I have the following code on that page that redirect users to the previous page but on click:
<script language="javascript">
$(document).ready(function() {
$('.goback').click(function() {
history.go(-1);
});
});
</script>
I want to automate the process so whenever they visit that page (page123.php) they redirected back to the previous one. I'd greatly appreciate it if anyone could help me in achieving this. Thank you.
Note: I don't want to use htaccess redirection.
You can add this tag to your html:
<meta http-equiv="refresh" content="1;url=yoururlhere" />
Related
I wonder if it's possible to navigate to a web page via link and zoom in to be 150%?
The only thing I could think about is to rewrite the '.click()' function and change the css there such as '-moz-transform', maybe something like this:
<!DOCTYPE html>
<meta charset="utf-8">
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<a href="https://www.google.com/search?q=kobe&igu=1" id="myLink" ></a>
</body>
<script>
$('#myLink').click(function() { zoom_page() });
function zoom_page()
{
// DO SOMETHING HERE!!
}
function autoClick() {
document.getElementById('myLink').click()
}
window.addEventListener("load", autoClick);
</script>
</html>
but not sure how exactly to do it.
Anyone can help? Thanks!
Andy
Given your example uses the URL of a well-known public site which you, almost certainly. have no control over: You can't do that.
Any JavaScript you run will apply to the current page and not the next one you navigate to.
If you could run JavaScript on arbitrary third-party websites then there would be a major XSS problem everywhere.
If you had control over the destination page then you could modify it with server-side code or JS embedded in the destination page contingent on data passed from the previous page (e.g. via the URL's query string).
If I click a button from page A, the browser will redirect to page B. In page B if I click a another button again it redirects to Page A. Here I used window.location.href to redirect the new page.
eg:window.location.href="http:\\localhost:12345\index2.html"
Is any other alternative way to redirect next page. I don't want to use windows.location
Update:
If I use windows.location the url which I come from is stored in document.reffer. For security purposes I don't want to allow to store the url.
Location assign() Method
You may use this method
example :-
function myFunction() {
location.assign("https://www.google.co.in");
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Load new document</button>
</body>
</html>
You can also use
window.location.replace("http://someUrl.com");
replace() does not keep the originating page in the session history.
Using $location in angularjs : See the documentation https://docs.angularjs.org/api/ng/service/$location
$url =$('<a/>')
$url.attr('href',"http://google.com");
$url[0].click()
You can try this.
You can use location.assign() for redirect another page.
location.assign("https://www.facebook.com/");
why not use <a>. what you only to do is give it a class like button.
Is there a way to configure in Chrome (or any browser) that whenever a webpage changes it automatically goes back to the previous page.
E.g. If a user presses a "Submit" button on a survey, they will be shown the "finish" message but then the original webpage with the survey will load again?
To go to previous page use
window.history.go(-1);
Example
<!DOCTYPE html>
<head>
<script>
function initialize(){
var submitBtn = document.getElementById("submitBtn");
submitBtn.addEventListener("click",function(){
alert("successfully submited");
setTimeout(goBack,2000)
});
function goBack(){
window.history.go(-1);
}
}
window.addEventListener("load",initialize);
</script>
</head>
<body>
<button id="submitBtn">Submit</button>
</body>
To go to a specific page
window.location = "";
While I'm not convinced it's a great idea, you know your requirements better than I do.
So to go back, you run this javascript.
window.history.back()
When you say immediately go back, I assume you want them to see the finish message first before being sent back after, say, 3 seconds?
<script>
setTimeout(function() {
window.history.back();
}, 3000);
</script>
Edit
If you want to redirect without javascript, you can use a meta tag in the header
<meta http-equiv="refresh" content="3; url=http://www.example.com" />
So if you use server side rendering you could reference the HTTP_REFERER header and inject it into your meta tag.
If you don't use server side rendering (PHP, MVC, React, etc) and you can't use javascript, then no; you're stuffed.
Is it possible -using only JavaScript and HTML- to have 3 pages with the following?
In Page1 there would be a button that when clicked it would redirect to Page2 for X seconds, and then redirect to Page 3.
I know it is possible using JavaScript in each page and timers, but what I don't know is if it can be done in one single JavaScript code in Page1, something like a timer and then redirect to the third page.
Basically, no. But then immediately contradicting myself: You could do it using frames, but I'm with Ixg when he/she says there's likely to be a better way to achieve your ultimate goal.
Basically, to do it with frames: The click on Page1 doesn't take you off Page1, but instead replaces Page1's content with an iframe that fills the entire page, loading its content from Page2. Then since the JavaScript environment of Page1 still exists, you can use a timer to redirect to Page3 when ready, all without any modifications to Page2 or Page3 (unless of course Page2 has frame-busting built into it).
For the record, this scenario can be implemented in one single page.
Say you have three pages, you want page1.html to redirect on click
<html>
<head>
<title>Page 1</title></head>
<body>This is page 1. <input type="button" onclick="toPage2()" value="Go to page 2." /></body></html>
to page2.html
<html>
<head>
<title>Page 2</title></head>
<body>This is page 2.</body></html>
and then have page2.html redirect to page3.html, after some time
<html>
<head>
<title>Page 3</title></head>
<body>This is page 3.</body></html>
All you need to do is get the source of page 2, inject some javascript into it and then load the source into the browser; this means page 2 does not need to be aware of the redirect behaviour. Thus, page 1 would become something like:
<html>
<head>
<title>Page 1</title>
<script>
// you can get the source of page 2 via ajax -- still meeting the requirement of javascript/html only.
var source2 = '<html><head><title>Page 2</title></head><body>This is page 2.</body></html>';
function toPage2 () {
var page2 = document.open('text/html', 'replace');
var source2injected = inject(source2, 3000, 'page3.html');
window.history.pushState('', '', 'page2.html');
page2.write(source2injected);
page2.close(); }
var left = "<script>setTimeout(function(){window.location='",
middle = "';},",
right = ");</scr" + "ipt>";
function inject (source, time, destination) {
return source.replace('<body>', left + destination + middle + time + right + '<body>'); }
</script></head>
<body>This is page 1. <input type="button" onclick="toPage2()" value="Go to page 2." /></body></html>
I am not saying that this is a good idea or the right solution for the problem you are actually trying to solve, but it does answer your question.
I am trying to code this for hours and still couldn't do it. It keep tell me "Permission Denied".
Here is what I am trying to accomplish. This pretty hard to explain please follow the example below.
For example. domain111.com and domain222.com.
When I am on domain111.com i click on the popup link , it will pop-up the domain111.com/popup.html then it redirect me to domain222.com. On this domain222.com it will redirect to couple pages before it redirect back to domain111.com with the result. I want to send the result from domain111.com to domain111.com.
The process is like below.
Domain111-popup to-->Domain111-redirect-->Domain222-redirect xxx Domain222 pages then redirect to-->-Domain111---SEND to parent window->Domain11
Here is my code.
File name 1.hml on domain111.com
<script type="text/javascript">
function IamParent() {
alert('I am the parent of this window')
}
function PopUP() {
window.open("http://domain222.com/2.htm", 'ALpop').focus();
}
</script>
<body>
<a href="#void(0);" onclick="PopUP();" >Click</a>
</body>
File name 2.html on domain222.com
<head>
<title></title>
<meta http-equiv="refresh" content="1;url=http://domain111.com/3.htm?Result=Yes" />
</head>
Filename 2.htm on domain111.com
<script type="text/javascript">
parent.IamParent(); //execute the function from the same domain111.com/1.htm
</script>
Please don't suggest AJAX or web request because it will not work with this case.
Thanks for reading.
Parent windows in other domains are inaccessible due to a security restriction requirement in the JavaScript engines. This applies to all browsers. It is a cross-site scripting attack prevention that cannot be disabled.