Essentially, all I want to do is open an external web page after the current page is loaded via java script.
open my page -> javascript tells browser to open external page -> external page being loaded into the broser
How may I accomplish this?
you may use this
<html>
<head>
<script type="text/javascript">
function load()
{
window.location.href = "http://externalpage.com";
}
</script>
</head>
<body onload="load()">
<h1>Hello World!</h1>
</body>
</html>
<html>
<head>
<script type="text/javascript">
function load()
{
window.location.href = "http://externalpage.com";
}
</script>
</head>
<body onload="load()">
<h1>Hello World!</h1>
</body>
</html>
Hope it should be window.location. Check the code.
Technically you can:
location.href = "http://example.net/";
… but you should perform an HTTP redirect instead as that is more reliable, faster and better food for search engines.
You can also use the "open" method to open the source file or url on a new window.
window.open("anyfile.*");
or
window.open("http://anylocation.com");
Hi please try this code for page loading time we will redirect whatever u configured the urls.
<!DOCTYPE html>
<html>
<head>
<script>
function myFunction() {
window.open('https://google.com');
}
</script>
</head>
<body onload="myFunction()">
</body>
</html>
<body>
<script>
document.body.innerHTML += 'Link';
document.getElementById("link").click();
</script>
<body>
Related
i tried to access website with different url names, example 'https://campus.champs.asia/mobile/login.php' but just write campus.champs.asia in browser and the result it should be same with content of campus.champs.asia/mobile/login.php.
the point is code in window.open is
window.open('https://campus.champs.asia','_self','location=yes');
but when i open it it should be content of
window.open('https://campus.champs.asia/mobile/login.php','_self','location=yes');
<html>
<head>
<title>NestorApp</title>
<script type = "text/javascript">
function gotoWeb()
{
window.open('https://campus.champs.asia/mobile/login.php','_self','location=yes');
}
</script>
It's not too clear what you're trying to do here.
I assume you want a user which navigates to https://campus.champs.asia automatically redirected to https://campus.champs.asia/mobile/login.php by the browser, do you?
In this case just place the following index.html file to https://campus.champs.asia
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
location.replace("https://campus.champs.asia/mobile/login.php");
</script>
</body>
</html>
I have a file in my directory which is constantly changing itself. So every 1 second my file is saved and has a diffenent content. How can I display the file content in a HTML site using javascript in a way that the file content is updated in real time or every 1 s?
I tried this code but the site just opens the pop-up window where the file content is and every time I want to see changes, I have to press F5, I don't want that.
<html>
<head>
</head>
<title>test</title>
<body>
test<br>
<script>
var w = window.open('output.txt'); //Required full file path.
w.print();
</script>
</body>
</html>
I would go along the lines of
</head>
<title>test</title>
<body>
test<br>
<div id="text" ></div>
<script>
setInterval(()=>{
let t=new XMLHttpRequest()
t.open('GET',location.origin+'output.txt')
t.onreadystatechange=(ev)=>{
if(ev.readyState==4){
document.getELementById('text').textContent=t.responseText;
}
};
t.send()
},1000);
</script>
</body>
</html>
this way you wont get a new popup every second
another way would be :
<html>
<head>
</head>
<title>test</title>
<body>
<br>
<iframe id="text" src="output.txt" />
<script>
setInterval(()=>{
document.getElementById("text").contentWindow.location.reload();
},1000);
</script>
</body>
</html>
Use the following code:
<html>
<head>
</head>
<title>test</title>
<body>
test<br>
<script>
var w = window.open('output.txt'); //Required full file path.
w.print();
setInterval(function() {
window.location.reload(true);
}, 1000)
</script>
</body>
</html>
I want to open hash #home automatically on page load. I tried
<body onload=window.location='#home'>
JS way:
<html>
<head>
<script type="text/javascript">
function load()
{
window.location.href = "#home";
}
</script>
</head>
<body onload="load()">
<h1>Hello World!</h1>
</body>
</html>
And html redirect
<meta http-equiv="refresh" content="0; url=#home" />
All ways are too slow (about 2-3 sec. to redirect after page load). Is there any better (faster) way to automatically open #home on page load?
Do this:
<body onload="window.location.hash='home'">
I think this is the fastest way.
To redirect to the specified tag, set the id of any div or control with "home".
<html>
<head>
<script type="text/javascript">
function load()
{
window.location.href = "#home";
}
</script>
</head>
<body onload="load()">
<h1>Hello World!</h1>
<div id="home">Some content</div>
</body>
</html>
I found best solution. There is no load time. It check hash and if there is no hash (first page load) open hash tab #home. Example:
<script type="text/javascript">
$(document).ready(function(){
var x = location.hash.replace("#","");
if (x==="")
{
window.location.href = "#home";
}
});
</script>
Really i tried many ways but this is the best and fastest.
Having problem to open form in new window, script is pulled from external service.
Take a look CODE on JSfiddle
regards
You can add a target attribute to the form after its been rendered;
<html>
<head>
<script type="text/javascript">
function fixform() {
//ism is created by the opentable.com script
document.forms["ism"].setAttribute("target", "_blank");
}
</script>
</head>
<body onload="fixform();">
<div id="book-table">
<div id="OT_searchWrapperAll">
<script type="text/JavaScript" src="http://www.opentable.com/ism/?rid=35449"></script>
<noscript id="OT_noscript">
Reserve Now on OpenTable.com
</noscript>
</div>
</div>
</body>
</html>
Update Try removing the onload="fixform();" and use the jQuery equivalent;
$(document).ready(function() {
document.forms["ism"].setAttribute("target", "_blank");
});
Why is it so that when you use window.parent.showMessage("Video Is OK"); inside a .js file you've included on a page, it won't work, but only if it's on the page itself..?
Can you fix this?
There are two scenarios that I can think of where you'd want to use window.parent. The first is when you have a window open another window using window.open. The other is where the first window uses an iframe to load a page. In the former case, it appears as though you actually want to use window.opener, as ukostin has said. In the latter case, window.parent works fine. Both methods work properly whether the code is inline or loaded from an external JS file. Here are some tests:
POPUP
parentWindow.htm:
<html>
<head>
<script>function showMsg(msg){alert(msg);}</script>
<body>
Open
</body>
</html>
externalWindow.js:
function showMsgExternal(msg){window.opener.showMsg(msg);}
childWindow.htm:
<html>
<head>
<script>function showMsgInline(msg){window.opener.showMsg(msg);}</script>
<script src="externalWindow.js"></script>
</head>
<body>
Inline
External
</body>
</html>
IFRAME
parentFrame.htm:
<html>
<head>
<script>function showMsg(msg){alert(msg);}</script>
</head>
<body>
<iframe src="childFrame.htm" width="300" height="100"></iframe>
</body>
</html>
externalFrame.js:
function showMsgExternal(msg){window.parent.showMsg(msg);}
childFrame.htm:
<html>
<head>
<script>function showMsgInline(msg){window.parent.showMsg(msg);}</script>
<script src="externalFrame.js"></script>
</head>
<body>
Inline
External
</body>
</html>
Try to use window.opener as link to the parent window.