I have small requirement that I am passing query string from demo1.html to demo2.html.
in demo2.html, there is back button(history.back()) so when user click back button it will redirect to demo1.html. in this demo1.html, I want to get querystring value or previous page url using javascript or jquery.
please find the demo html script below for your reference.
I need the query string value of demo2 page in demo1
demo1.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of the document</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head>
<script>
function display()
{
var wind = document.referrer;
var preUrl = window.location.protocol;
alert(wind);alert(preUrl);
}
</script>
<body>
Search Content of the document......
Search
Display
</body>
</html>
demo2.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of the document</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head>
<script>
function goBack() {
window.history.back();
return false;
}
</script>
<body>
demo 2 Content of the document......
Back
</body>
</html>
Reards
siva
Save the query string in the href that acts as the back button, then use location.replace()
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of the document</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head>
<body>
demo 2 Content of the document......
Back
</body>
</html>
a) Use the solution offered ny user3036342. This won't make the actual browser Back button work as you want though.
b) Leave the query string alone and use cookies instead. Set the cookie in demo2 and make sure demo1 reloads (I found this but there might be a better way)
c) If the pages are on the same domain, you could use History API and AJAX to switch between demo1 and demo2. Then you have full control about what happens when user presses Back/Forward, but it will require some reading to understand.
Related
New to HTML and javascript. I'm trying to update a number that changes in another program without having to refresh the entire webpage using javascript. My home html page is as follows:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Title</title>
<script type="text/javascript" src="Scripts/jquery-3.2.1.min.js"></script>
</head>
<body>
Counter
<div id="counter"><h2>0</h2></div>
<button>Update</button>
</body>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("#counter").load("value.html #count");
})
});
</script>
</html>
When I press the button, nothing changes. value.html contains:
<div id="count">:="DB1".counter:</div>
which is just an int value that counts up every second. If I load up this page, it shows the correct int value. But for some reason, the id="counter" never updates on the main html page. I've tried on chrome and internet explorer with no luck. Any help would be greatly appreciated.
I have some links (like first link in below) and want to get links that is redirected to (like second one)
For example:
I have link below:
http://dx.doi.org/10.1007/146.1435-5655
And need to get this link:
http://link.springer.com/journal/146
that redirect (or converted) from first one.
When I use .load() function in jQuery it return some javascript codes that I think it get second link from dx.doi.org server.
How can I get second link? (http://link.springer.com/journal/146)
In other word, I have http://dx.doi.org/10.1007/146.1435-5655 and need only http://link.springer.com/journal/146 in string (not content of http://link.springer.com/journal/146)
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div id="swPicForm">TODO write content</div>
<script type="text/javascript" src="js/jquery/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
$("#swPicForm").load("http://dx.doi.org/10.1007/146.1435-5655", null, function() {
alert($("#swPicForm").html());
});
</script>
</body>
</html>
Result is:
function (e){return v.access(this,function(e){var n=this[0]||{},r=0,i=this.length;if(e===t)return n.nodeType===1?n.innerHTML.replace(ht,""):t;if(typeof e=="string"&&!yt.test(e)&&(v.support.htmlSerialize||!wt.test(e))&&(v.support.leadingWhitespace||!pt.test(e))&&!Nt[(vt.exec(e)||["",""])[1].toLowerCase()]){e=e.replace(dt,"<$1></$2>");try{for(;r<i;r++)n=this[r]||{},n.nodeType===1&&(v.cleanData(n.getElementsByTagName("*")),n.innerHTML=e);n=0}catch(s){}}n&&this.empty().append(e)},null,e,arguments.length)}
thanks all
I have some JavaScript which needs access to some data available on the server. In the past, I just used PHP to include some JavaScript in the original page download which would create an object, and used that. I would like to try doing so differently, and instead download some JSON and use that.
How is this accomplished. I made up the following and don't know if it is the "right" way.
Thanks
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Testing</title>
<script type="text/javascript">
//Disable all events using JavaScript. How is this done?
</script>
</head>
<body>
<script type="text/javascript">
//Allow events which were previously disabled
//$(function(){}); not needed since end of the page
$.getJSON( 'getMyJSONstuff.php', function(myJSONstuff) {
$('#elem1').plugin1({x:myJSONstuff.x});
$('#elem2').plugin2({y:myJSONstuff.y});
});
$('#elem3').plugin2({y:123});
$('#elem4').plugin3({z:321});
</script>
</body>
</html>
Im begginer in WebProgramming so maybe my questuion will seem naive to some of you.
I want to run a simple JavaScript function without any click to implement a redirection.
I try this:
#inherits System.Web.WebPages.WebPage
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
#Styles.Render("~/Content/css")
#Scripts.Render("~/bundles/modernizr")
#Scripts.Render("~/bundles/jquery")
</head>
<body>
</body>
</html>
But it dosen't work.
Any idea wat I am missing?
Thank you in advance.
Simply use window.location="http://www.newlocation.com". See the example below:
<head>
<script type="text/javascript">
<!--
function Redirect()
{
window.location="http://www.newlocation.com";
}
document.write("You will be redirected to main page in 10 sec.");
setTimeout('Redirect()', 10000);
//-->
</script>
</head>
More info here
You can use Meta tag for client side redirection.
<META http-equiv="refresh" content="5;URL=http://www.example.com">
Which will redirect the user to http://www.example.com after 5 seconds.
window.location is a property of window object.
You can try function version too
function myCustomHref() {
window.open ('http://www.newlocation.com', '_self');
}
Here you can find more optional properties
if you want to redirect from a webpage to another using javascript,then you can try the following script,
<script>
function newPage() {
window.location.assign("http://www.w3schools.com")
}
</script>
For full details you can view the following website,
http://www.w3schools.com/js/js_window_location.asp
I had recently posted a question regarding my problem here.
When i click on a SUBMIT BUTTON or a LINK, I do not want the history of the page where the user clicked the BUTTON or LINK to get recorded in browser.
I received a suggestion to use history.pushState(). But I am not familiar with the function and I urgently need the solution to work.
I still not sure as to what to do. But can anyone suggest me whether I can use this to solve my problem.
<input type="submit" onclick="location.replace(this.href); return false;"/>
Continue
Example : I have a page bar.html which has a link Foo. When the user clicks on the link, he should be redirected to foo.html and browser history of bar.html should not get recorded so that the user cannot use BACK button to get back on this page.
Edit: Also how can I force the browser not to store a certain page in cache, so the next time user visits, the browser requests the server for the page.
For chnage page with JS, use code like this:
Continue
But i don't sure about it history work.
Here is an working example:
File: a.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>A</title>
</head>
<body>
<h1>A</h1>
B
</body>
</html>
File: b.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>B</title>
<script>
window.location.replace('c.html');
</script>
</head>
<body>
<h1>B</h1>
C
</body>
</html>
File: c.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>B</title>
</head>
<body>
<h1>C</h1>
</body>
</html>