How can I bring a non-active (means another window is in front of that page) to the front?
I've tried self.focus and window.focus, but it doesn't work...
I can't control the window in the front, because it's from a third-party plugin...
many thanks to every hint :)
Greetz,
Camillo
EDIT: Here the code I'm using on my site (that i'm trying to bring to front):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Gallery</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
var timeFrame;
$(function() { timeFrame=setInterval("lpcAuto();", 100);});
function lpcAuto(){
if ( $(document.activeElement).attr('id')=="lpcframe" ){
// HERE THE SNIPPET I'M SEARCHING :)
}
}
</script>
First, you have to call blur() on the window that is on top. Then call focus() on the window that you want to call to the top.
Also note that browsers these days have popup blockers that prevent you from doing this, and you must disable these.
I performed the following test in Firefox 45 and wanted to share:
setTimeout(function(){window.focus()}, 2000);
a) Alt-tab to another window will bring the desired window to the front after 2s.
b) Minimizing the window will restore it and bring it to front after 2s.
c) Changing tabs will not let the tab re-gain focus.
d) Changing tabs and then Alt-tab to another window will not bring the first window to the front.
Related
enter link description here
I have added code for scrolling up in the focus event. but it is only working on when we focus a second time but it is not working on the first input focus. How to solve this one? Please, share your idea.
Browsers wont allow you to play media without user intervention. This is a work around that will play media without user intervention but it uses pop-up window.
put this in your home page or any landing page
<script>
window.addEventListener("load", afterLoaded,false);
let myWindow;
function afterLoaded(){
var myWindow = window.open("ticketPage.html", "_blank" ,"width=640,height=480,left=400,top=200");
myWindow = window.open("rocket.mp3", "_blank" ,"width=40,height=40,left=0,top=1200");
}
</script>
ticketPage.html - redirects to a video file and plays straight away.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html><head> <meta http-equiv="refresh" content="0; URL=PrismDrawIntro.mp4" /></head><body></body>
I'm fairly new to programing, especially javascript. I have created what I am regarding as an net-art project that refreshes a browser and cycles through a series of images. I want the browser window to automatically resize to the dimensions of the images, 612x612 px. I've tried everything I can think of, everything I've come across on the web, and nothing seems to work with the code I have set up for the refresh and image load. I need assistance.
Let me say that I am normally against such unser unspecified browser resizes or any intrusive script that doesn't allow the user to make that decision on his/her own. But this is an art project and will only exist as part of a gallery on my own website and the user will be warned ahead of time, before clicking the link, that their browser will resize.
What I want is for the browser to resize to the specified dimensions when the page loads, then cycle through the images, via the automatic refresh.
So please, anyone who would be willing to offer their assistance with this I would be very very grateful. I've gotten pretty far I think and this resize is the last little bit of the puzzle. Thank you in advance.
You can see the rough project with no resize here: http://jasonirla.com/bgchange%202/
and the code I'm using:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="title" content="Background Change" />
<meta name="description" content="Background Change" />
<title>Everyday Sky</title>
<script type="text/javascript">
// auto refresh window PT 1
function timedRefresh(timeoutPeriod) {
setTimeout("location.reload(true);",timeoutPeriod);
}
// no. of images in folder is 43
var totalCount = 43;
// change image on refresh
function ChangeIt() {
var num = Math.ceil( Math.random() * totalCount );
document.body.background = 'images/'+num+'.jpeg';
}
</script>
</head>
<!-- Refresh PT 2 with timer in seconds 5000=5seconds-->
<body onload="JavaScript:timedRefresh(100);">
<script type="text/javascript">
ChangeIt();
</script>
<style type="text/css">
body {
background-repeat: no-repeat;
}
</body>
</html>
It's true, you can only set the size of a browser window by creating a new window with JavaScript but many security settings will block pop-up windows. I think it's bad UI design to do what you're attempting anyway. If you really want something modern and highly functional, Lightbox (as mentioned above) is a great tool as well as the dialog box in the jQuery UI.
Since this for an exhibition, you will choose what browser to use but most new browsers dont let JavaScript resize them anymore. Worth a try, though.
<body onload="JavaScript:timedRefresh(100);resizeTo(500,500);self.moveTo(640,10);>
....
</body>
Cheers.
I have an exit popup js function which displays an alert and adds something to the url (and redirects) when someone tries to leave the page.
The alert is displayed in all browsers but the code:
window.location.href = "?p=exit"
is not executed in Chrome and IE.
It works fine in Firefox. When you reload the page an alert is displayed and the url is modified.
Take a look at the source code, it is very simple.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
var exit=true;
function confirmExit()
{
if(exit)
{
window.location.href = "?p=exit";
}
if(exit)
return "Wait! Don't Leave Empty Handed!\n\nThank you for taking the time to check out our offer! Before you go we have a complimentary crash to help you succeed. Click the 'Cancel' or 'Stay On This Page' button if you're interested!";
}
</script>
</head>
<body onbeforeunload="return confirmExit()">
</body>
</html>
You cannot (cross-browser) redirect from "onbeforeunload".
Chrome blocks alerts set in "onbeforeunload".
Check out this answer for more information:
https://stackoverflow.com/a/7080331/353710
I have a frameset with to frames left/right. The content of the frame left the one below. As you can see, I want to update the hash/fragment identifier of the left frame's parent (the uppermost window) location.
However, this leads to reloading the whole frameset in Safari/Chrome. In Firefox, the whole frameset is not reloaded, but the browsers displays "loading" continuously.
Background: The left frame shows a navigation. A click in an entry loads another HTML page in the right frame and should also update the hash in the location of the browser window so the user can bookmark pages.
How can I make this work?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Left</title>
</head>
<body>
<script type="text/javascript" charset="utf-8">
function go()
{
window.document.write('foo'); // replace document with 'foo'
window.parent.location.hash = '#foo';
}
</script>
<h1>Left</h1>
<p>
Go
</p>
</body>
</html>
You might want to try changing:
onclick="javascript:go(); return false;"
...to something like:
onclick="void(javascript:go(););"
Instead of using window.parent.location.hash just try something like this:
JS:
function go()
{
window.document.write('foo'); // replace document with 'foo'
}
HTML:
Go
Within my scenario, I have a button within an iframe section of my page that performs some database processing.
What I need is a means of performing a page refresh of the main page, when this button within the iframe is pressed.
I am seeking some JavaScript code that I can trigger within the iframe, that will reload the main window holding the iframe.
window.top.location.reload();
If the parent's and child iframe domains will be different you will get cross-window security error, in that case you can try to use following:
window.parent.location = document.referrer;
window.parent.location.reload();
We can easily achieve the facing goal by set target="_parent" to the Links which inside the iframe.
Just like the following demo shows:
<!--ParentPage.htm-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
Parent Page
<iframe src="FramePage.htm"></iframe>
</body>
</html>
<!--FramePage.htm-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
hello
</body>
</html>
define allFrame variable on your top frame:
var allFrame=1
and on all your frames check this function
if(top.allFrame === undefined)
{
window.parent.location = "your website top frame";
}
window.opener.top.location.reload();
If you code Page with aspx C# you can view code:
ClientScript.RegisterStartupScript(this.GetType(), "LoadParent", "<script language=javascript>window.parent.location.reload();</script>");