lots of way possible ..
1.
<script language="javascript" type="text/javascript">
window.location.href="login.jsp?backurl="+window.location.href;
</script>
2.
<script language="javascript">
alert("back");
window.history.back(-1);
</script>
3.
<script language="javascript">
window.navigate("top.jsp");
</script>
4.
<script language="JavaScript">
self.location="top.htm";
</script>
5.
<script language="javascript">
alert("Access Violation");
top.location="error.jsp";
</script>
6.
<script language="javascript">
window.location = window.location.host;
</script>
Answer from Govind Singh on Stack Overflowlots of way possible ..
1.
<script language="javascript" type="text/javascript">
window.location.href="login.jsp?backurl="+window.location.href;
</script>
2.
<script language="javascript">
alert("back");
window.history.back(-1);
</script>
3.
<script language="javascript">
window.navigate("top.jsp");
</script>
4.
<script language="JavaScript">
self.location="top.htm";
</script>
5.
<script language="javascript">
alert("Access Violation");
top.location="error.jsp";
</script>
6.
<script language="javascript">
window.location = window.location.host;
</script>
check this question here.you can use
// similar behavior as an HTTP redirect
window.location.replace("http://stackoverflow.com");
// similar behavior as clicking on a link
window.location.href = "http://stackoverflow.com";
If you are trying to open a html file, from the same folder you can use the following javascript code :
location.replace("./name_of_the_file.html")
Don't forget the double quotes. If you want to open another website, you can use the following javascript code:
location.replace("https://stackoverflow.com")
well there are some issues here :)
1) jump to a new page using window.location="mypage.html" (remember the double quotes, single do as well)
2) you seem to forget about double quoting: document.getElementById("compiler").style.display="block";
3) you cannot refer to the "compiler" element from your function because when you get there, you have already loaded the new page. You can do something like this:
window.location="mypage.html?id=compiler"
And in your mypage.html:
<head>
<script>
function display() {
var id = parseURL();
document.getElementById(id).style.display="block";
}
function parseURL() {
refer to: https://stackoverflow.com/questions/831030/how-to-get-get-request-parameters-in-javascript
}
</script>
</head>
<body onload="display()">
....
the idea is to pass the id of the element to be displayed to the new page via GET parameter and then get it back from the URL in the new page. Refer to How to get "GET" request parameters in JavaScript?
Mauro
This worked for me fine:
File 1:
<html>
<head></head>
<body>
<a href="#" onclick="window.open('file:///D:/Examples/file2.html'); return false">CLICK ME</a>
</body>
<footer></footer>
</html>
File 2:
<html>
...
</html>
This method works regardless of whether or not the 2 files are in the same directory, BUT both files must be local.
For obvious security reasons, if File 1 is located on a remote server you absolutely cannot open a file on some client's host computer and trying to do so will open a blank target.
window.location.href = 'file://///fileserver/upload/Old_Upload/05_06_2019/THRESHOLD/BBH/Look/chrs/Delia';
Nothing Worked for me.
I would not recomend you to use document.write as others suggest, because if you will open such window twice your HTML will be duplicated 2 times (or more).
Use innerHTML instead
var win = window.open("", "Title", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=780,height=200,top="+(screen.height-400)+",left="+(screen.width-840));
win.document.body.innerHTML = "HTML";
You can use window.open to open a new window/tab (according to browser setting) in JavaScript.
By using document.write you can write HTML content to the opened window.
In the main.html:
<input type='button' onclick='location.href=test.html' value='click me'>
in test.html
function create() {
// Write something in the page
}
<body onload='create()'>
</body>
function create()
{
window.location = 'test.html';
}
This is your starting point. Then, you need to add some PHP or JS to your test.html file.
Method 1: PHP
For example, you can get a message from the URL, that you're going to write.
Main file: function create() { window.location = 'test.php?p=Hello%World'; } Test file:
Method 2: JS
You can also write a JS function in your test file, which is called as soon as the page is loaded.
Main file:
function create() // Create function on 1st page
{
window.location = 'test.html';
}
Test file:
<head>
<script type="text/javascript">
function message()
{
document.getElementById('container').innerHTML = 'Hello world';
}
</script>
</head>
<body onload="message();">
<div id="container"></div>
</body>
Hope it helped.
Use window.open():
<a onclick="window.open(document.URL, '_blank', 'location=yes,height=570,width=520,scrollbars=yes,status=yes');">
Share Page
</a>
This will create a link titled Share Page which opens the current url in a new window with a height of 570 and width of 520.
Just use window.open() function? The third parameter lets you specify window size.
Example
var strWindowFeatures = "location=yes,height=570,width=520,scrollbars=yes,status=yes";
var URL = "https://www.linkedin.com/cws/share?mini=true&url=" + location.href;
var win = window.open(URL, "_blank", strWindowFeatures);
Hello all !
I tried to open the index.html of a folder containing HTML and Javascript.
When I double click on the index.html, it's just a blank page.
What am I missing pls ?
Thank you so much !
In the HTML there is:
<html> <head> <title>My First Web Page</title> <script src="myComponents/index.js" type="module"></script> </head> <body> <my-audio src="https://alinkofsound.mp3"> </my-audio> </body> </html>
In my component folder, there is a javascript folder containing different elements to have the page do this.
The issue is that it works in codepenio..
Try:
var html = popup.document.documentElement.outerHTML
EDIT
The window is not loaded immediately. Something like this will work, assuming that you're not attempting to violate the same-origin policy:
$('#btn').click(function() {
var popup = window.open('[Your URL HERE]', '_blank', 'width=500,height=500');
popup.onload = function() {
setTimeout(function(){ console.log(popup.document.documentElement.outerHTML) }, 2000);
}
});
Here's a working fiddle.
Note: If you control both the parent and the child source, you could also have the child invoke a method on the parent that passes in it's html:
Child Window
// Call when body is loaded
function SendHtmlToParent() {
window.opener.HtmlReceiver(document.outerHTML);
}
Parent
function HtmlReceiver(html) {
console.log(html);
}
Wait...
Note that remote URLs won't load immediately. When window.open() returns, the window always contains about:blank. The actual fetching of the URL is deferred and starts after the current script block finishes executing. The window creation and the loading of the referenced resource are done asynchronously.
MDN
And if you wait, you will get this error:
Unsafe JavaScript attempt to access frame with URL https://www.google.co.il/ from frame with URL http://fiddle.jshell.net/_display/. Domains, protocols and ports must match.
So it can be done with google, unless you're working there...
Fiddle
If you open something "valid" it will work fine.
Working DEMO