For example:
<html>
......
<iframe name="first">
<html>
......
<iframe name="second"></iframe>
<iframe name="third"></iframe>
......
</html>
</iframe>
......
</html>
I want the third or second iframe to open the link which is clicked, open in the first frame. Target attribute not work.
It is possible ? if yes, then how to do it ?
You can control where an iframe opens up with the target attribute on the <a> tag:
http://www.w3schools.com/tags/att_a_target.asp
_blank: Opens the linked document in a new window or tab
_self: Opens the linked document in the same frame as it was clicked (this is default)
_parent: Opens the linked document in the parent frame
_top: Opens the linked document in the full body of the window
framename: Opens the linked document in a named frame
var WindowSrc = $("#second").attr("src");
window.open(WindowSrc);
Note: You will need to ensure that pop ups are allowed if you wish to open a new window.
Related
I'm trying to make a random link picker - When I press the button, the link goes in the current tab. I'm trying to make it so it will go into a new one.
<script type="text/javascript">
function randomlinks(){
var myrandom=Math.round(Math.random()*2)
var links=new Array()
links[0]="link1.com"
links[1]="link2.com"
links[2]="link3.com"
window.location=links[myrandom]
}
</script>
<form>
<input type="button" value="Random Episode!" onClick="randomlinks()">
</form>
Change it from:
//This sets the location of the current window, which you don't want
window.location = links[myrandom];
To this:
//This says to open a new tab or window, based on the user browser settings, to the url
window.open(links[myrandom]);
Just replace the line
window.location=links[myrandom]
with
window.open(links[myRandom], '_blank');
The target attribute specifies where to open the linked document.
You also have to check your browser settings first. If they are set to new window you can click your whole lifetime and it will still be opened in a new window instead of a new tab.
These are the right attributes.
The target attribute can have one of the following values:
_blank - Opens the linked document in a new window or tab
_self - Opens the linked document in the same window/tab as it was clicked (this is default)
_parent - Opens the linked document in the parent frame
_top - Opens the linked document in the full body of the window
framename - Opens the linked document in a named frame
So, this means that the default value (without the target attribute)
window.location=links[myrandom]
is also working. Hope it helps that your scripts work lovely.
I want to create an iframe of size 200X200. and i want to use a popup code in it. but i am facing a problem,
currently the pop up is showing when i click on the space 200x200 but i want the popup to be displayed when i click on the page which have the iframe. (not only the iframe area but the whole page)
whenever i place the iframe on a page i want the popup to be apear as it's the popup of the original page not the iframe only.
Any one have any idea how i can perform this action with html, javascript or jquery?
Thanks
Use autoresize javascript code
<script type="Text/JavaScript" language="JavaScript">
<!--
function resize_iframe()
{
var height=window.innerWidth;//Firefox
if (document.body.clientHeight)
{
height=document.body.clientHeight;//IE
}
//resize the iframe according to the size of the
//window (all these should be on the same line)
document.getElementById("cam").style.height=parseInt(height-
document.getElementById("cam").offsetTop-8)+"px";
}
// this will resize the iframe every
// time you change the size of the window.
window.onresize=resize_iframe;
//Instead of using this you can use:
// <BODY onresize="resize_iframe()">
</script>
</head>
<body>
<iframe id="cam" width="100%" scrolling="yes" src="http://www.your_page.com" onload="resize_iframe()">
</iframe>
</body>
this will help for you
Make the pop-up call when the user click in an element of the body, not only the frame.
If you provide your JavaScript & HTML code, I can help you more.
I have been facing a problem.I am able to open a window using window.open method.If I specify the height and width of the window,it opens as a pop up window.If no parameters is given for height or width,then it opens in a new tab.
Is there any property through which I can determine window opened was a pop up or a new tab?
Thank you
Malcolm X
Edit: I have been looking into this a little further.
Seems like there is no different "type" on these windows, simply different options.
A way I found to check if it was a tab or window is to check window.menubar.visible.
For the tab, which is a full and normal window it is true, and for the pop-up the menu is hidden and therefore false. Same applies to window.toolbar.visible.
Works in FF and Chrome at least. Unfortunately not in IE. (Testing done in IE8, which is the version I have installed. For testing of course..)
Example:
if(window.menubar.visible) {
//Tab
} else {
//"Child" Window
}
Found this thread: Internet Explorer 8 JS Error: 'window.toolbar.visible' is null or not an object
If you specify width and height, it means that you also have to specify the name parameter. This can be used in the same way target in an a tag is used, and defaults to _blank.
If you do not specify width and height I assume you also don't specify name and therefore it is opened with name=_blank, which means a new Tab.
If you specify width and height, are you setting a custom name? Doing so results in a child window. If you specify a name, or empty string as name, I suggest you try name:_blank if you want it to be a new tab.
If the window was opened with a name, you can always the window.parent from the child window. If you open with _blank I am not sure if you can get the window.parent
w3schools Window Open
I'm not quite sure what you mean in your question but from what I understand, you might want to use the HTML target attribute:
_blank Opens the linked document in a new window or tab
_self Opens the linked document in the same frame as it was clicked (this is default)
_parent Opens the linked document in the parent frame
_top Opens the linked document in the full body of the window
framename Opens the linked document in a named frame
Source: http://www.w3schools.com/tags/att_a_target.asp
You can detect that using onblur, by checking whether the focus is missed or not
<html>
<head>
<script>
function newTab() {
document.getElementById("demo").innerHTML = "New tab opened!<br><br>refesh this page to recheck ";
}
window.onblur = newTab;
</script>
</head>
<body>
<div id="demo">
Open a new tab and then check this page
</div>
</body>
</html>
I want to set location of parent window from pop up window opened by iframe.
I am writing this line of code in javascript but it is not working.
window.opener.parent.location = '../Account/';
try
window.opener.parent.location.href = '../account/';
Should work with
window.parent.location.href = '../account/';
try some thing like this
<b>iframe starts here</b><br><br>
<iframe src='iframe1.html'></iframe>
<br><br>
<b>iframe ends here</b>
<script type="text/javascript">
function change_parent_url(url)
{
document.location=url;
}
</script>
In iframe
<a href="javascript:parent.change_parent_url('http://yahoo.com');">
Click here to change parent URL </a>
So you can see that child iframe calls parent's function and gives URL
I need to trigger a function when the iframe loads a second time (the user clicks some link in the iframe). When the iframe page changes I can set the window location to the iframe src.
What I thought would be best is to set an onLoad attribute on the iframe element after the first load. I guess I would need the live event to tell when the iframe has been created, since it's dynamic.
This is what I had in mind:
$(document).ready(function() {
$('#tenant_login').fancybox({type:'iframe'});
$('#tenant_login').click(function() {
$('#fancybox-frame').attr('onload', function() {
window.location = $('#fancybox-iframe').attr('src');
});
});
});
If it matters the iframe is not cross domain.
$("#fancybox-iframe").load(function(){
window.location = $('#fancybox-iframe').attr('src');
});
This will allow you to redirect the parent window when the iframe loads a different page.
If you have control of the iframe content, as I did setting a target="_top" attribute on the hyperlink means the browser will open the link in the browser window rather than the iframe.
Main document:
<html>
<body>
<h1>The Main Page</h1>
<iframe src="myIframe.html" />
</body>
<html>
Iframe document:
<h2>The IFRAME</h2>
<a href="something.html" target="_top" >
This will open in the browser window rather than any iframe it exists in.
</a>
If you can't put target="_top" on the links of the iframe DOM you will need to capture the click events with javascript from the parent DOM.