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
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>
Change iframe's window's parent
Is it possible to change the contentWindow.parent of an iframe. What I want to do is:
window.document.getElementById('myframe').contentWindow.parent = window.document.getElementById('myframe').contentWindow.window
The above works in Firefox, Chrome, Opera but not IE.
The reason for doing this my iframe (let's call it TOP) itself has iframes in it (let's call them SUBWINDOWS), and both of them have Javascript that calls "parent.document.getElementById" and such. When you are in a top level window then parent.document.getElementId is the same as document.getElementById because for a top level window parent == window. For the iframe SUBWINDOWS parent.document refers to the the document of the top level window. Seems a bit sloppy, but it works, relying on the fact that parent == window for a top level window.
But now that top level window TOP is now an iframe in a bigger page (let's call it BIG). The Javascript in TOP that does parent.document.getElementById is now referring to BIG's document, whereas before it was referring to TOP's document.
So one quick and easy fix is to change the iframe's parent to point to itself. And this indeed works for Firefox, Chrome, Opera.
Any ideas for how to get it to work for IE?
--
My test code is:
test.html:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<p>Text outside iframe</p>
<iframe id="myframe" src="test_more.html"></iframe>
</body>
</html>
test_more.html:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<p>Text inside iframe</p>
<input type="button" value="window/parent" onclick="alert('window.location.href = ' + window.location.href + '\nparent.location.href = ' + parent.location.href);"/>
</body>
</html>
Put these files on a web server to avoid the same origin policy error and go to the URL like localhost:6144/test/test.html.
I want to display another html page on my html page, that html page is generated. So I don't have it's src, only the content. It has doctype, head, body, all stuff. So I decided to use iframe. The problem is that I can't assign the whole text to a variable, as I get errors, that there is an unsupported character, like "<" etc. How to deal with it?
I'm trying to do something like this:
window.onload = function() {
var iframeDocument = document.getElementById("myIframe").contentDocument;
var ss = "
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
</head>
<body>
</body>
</html>";
iframeDocument.write(ss);
iframeDocument.close();
}
So my problem is how to escape that text so it won't cause browser errors?
Also html content is generated dynamically, so in my code there is no that text, there is struts action variable. But after my code gots executed in browser, that's what I see in there.
The easiest way to solve this is to create a new aspx page, that creates that html you need in your iframe and set the src of the iframe to that aspx page (or php, depends on what you are using).
So lets say you create a new aspx page called Frame.aspx. You then add <iframe src="Frame.aspx?SomeParameter=SomeValue" /> to your parent window.
This is a much nicer approach and much more maintainable. Also it prevents having the iFrame contents twice (once in your javascript variable and once as content of the iframe).
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.
I have one page where I am using tag. As a source of this iframe I am passing one external webapp. Now when this app is loading, in its home page it has code which checks whether the app is loading inside frame or in parent window. If it is not in parent window then it is getting the refrence to parent window and change the location in such a way that it display itself in parent window.
Now I dont have control over this web app so I cannnot change it's home page, is there any workaround where I can stop this application to change it's parent window location. Here is the sample code I am using. I cannot give the url of the internal webapp. Before I see the alter msg "test", webapp is changing the location of the parent window.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Example</title>
<style type="text/css">
</style>
<script type="text/javascript">
// <![CDATA[
window.onload = function()
{
alert('test');
//frames["my_iframe"].onload = function()
//{
//alert("hey");
//}
//this also works for me:
document.getElementById("my_iframe").onload = function()
{
alert("hey");
}
}
// ]]>
</script>
</head>
<body>
Testing iframe....<br>
<iframe name="my_iframe" id="my_iframe" src="http://mywebapp.com" width="100%" height="100%" ></iframe>
</body>
</html>
You are trying to do what is referred to as XSS or cross site scripting, and is, for obvious reasons, impossible in any modern browser due to security mechanisms.
This article discuss this question and offers a 'solution', so to speak.
We Done Been ... Framed!
It's actually about avoid been framed (as the webapp you talk about does) but at the end there seems to be a way to frame any page...