I have a page which work like a navigation and a iframe in this page which show the content.
Now there are some situation when the inner page is directly shown in the browser.
eg: if somebody types the inner page's url in the browser address bar, the page is displayed in the window.
I want to prevent this.
Better still, I would like to redirect to any other page.
window.parent: The window object that contains the frame. If the the window is the top level window then window.parent refers the window itself. (It is never null.)
window.top: The top level window object, even if the current window is the top level window object.
window.self: The current window object. (It is a synonym of window.)
So, I'd write my check like this:
if (window.top == window.self) {
window.location = "index.html";
}
Which would be identical to the slightly more ambiguous:
if (window.top == window) {
window.location = "index.html";
}
<script language="Javascript"><!--
if (top.location == self.location) {
top.location = "index.html" // must be viewed in main index
}
//--></script>
modified it from a situation where an an iframe decides to become the main frame.
Related
I have two iframes on my page, frameOne and frameTwo.
I'm trying to refresh/reload frameOne from a script running in frameTwo.
function reload(){
srcLink = parent.document.getElementById('frameOne').src;
parent.document.getElementById('frameOne').src=srcLink;
}
This works but it refreshes to the initial value of the iframe.
IE:
If the parent page loaded with that iframe's src set to 'google.com' but then changed to (due to a user action) 'yahoo.com' my code will refresh that page to 'google.com', the link it was set to when the page was loaded. I would like to take into account the change of link and refresh that one.
Try this from frames[1] (the 2nd iframe page):
function changeFrameSrc(becauseURL, changeURL){
var bc = new RegExp(becauseURL, 'i');
if(bc.test(location)){
parent.frames[0].src = changeURL;
}
}
Using MVC 4 I add a blank window and hide it. On a button click I call this javascript to get content and center the window:
var win = $("#myWindow").data("kendoWindow");
win.content("Loading...");
win.refresh({
url: "#Url.Action("MyAction", "MyController")",
data: { userloginid: "AAA" }
});
win.center();
win.open();
The content is larger than a default window so the win.center() calculation is off, putting the window too far down.
How do I get the window to center based on the content it got via the refresh() command.
The problem seems to be, that you center the window, and than, some time after that, the new content is finished loading.
In other words: The center is called before the window get's its new size through the loaded content.
To prevent this, you should bind to the refresh event of the window, and center in that.
Something along the lines (beware: only register this event once):
var win = $("#myWindow").data("kendoWindow");
win.bind("refresh", function() {
win.center();
win.open();
});
How to catch click on an iframe using JQuery. I have an Amazon banner, and I need to close its container DIV when the user clicks the iframe. I've tried 'contents', onclick on iframe, binding the event but nothing works. When I click the iframe it opens Amazon's page on another tab, but the click event never fires. I put a breakpoint and alert just to make sure.
I am using latest JQuery version 1.9 and tested it on Chrome. I also thought about capturing a global click ($(document).click) and check the area of the click, but when I click the iframe, $(document).click doesn't fire. Any suggestions?
Again, it's an Amazon banner iframe, it's hosted on Amazon not on my server.
Example of the regular on binding that doesn't work: http://jsbin.com/oyanis/4/edit
There is a neat trick to get a "click" on on iframe content.
You could do:
<div id="iframeinside">
<iframe />
</div>
This now makes it possible to say in js something like:
var oldActive = document.activeElement; /* getting active Element */
var frame = $('#iframeinside iframe')[0];
$('#iframeinside').mouseenter(function() {
/* Setting interval to 1ms for getting eventually x,y mouse coords*/
oldActive = document.activeElement;
setInterval('doSomething()', 1);
});
$('#iframeinside').mouseleave(function () {
/* clear interval cause we arent over the element anymore*/
clearInterval(intervalId);
});
These intervals do call:
function doSomething() {
/* if the focus has changed to the iframe */
if(oldActive != frame && document.activeElement == frame) {
oldActive = document.activeElement;
alert(myQuery);
alert('click did happen to the iframe');
}
}
I used this for several things and it always worked. What i didnt check was how about ie6,7 and older brothers.
I am trying to print a multiple-page FlexPrintJob, that includes on the first page, several labels, then a PrintDataGrid. It all prints, except that the PrintDataGrid only prints using half the page on all the pages.
I know it has to do with the labels that I am printing on page 1, because taking them off or hiding them fixes the issue and the grid prints full page all pages.
I have tried various containers around the grid and labels, including VBox, VGroup, Group, and specifying different combinations of height="100%" for some of the containers.
Is it simply not possible to print a half page of variables / labels on page 1, then start the data grid on the same page (half page worth), but then have it go to full page on the following pages?
Here is my print job code:
var printJob:FlexPrintJob = new FlexPrintJob();
if (printJob.start()) {
var thePrintView:printViewEventUser = new printViewEventUser(); // Create a FormPrintView control as a child of the application.
addElement(thePrintView);
thePrintView.width=printJob.pageWidth;
thePrintView.height=printJob.pageHeight;
thePrintView.parentEncounter=parentEncounter; //pass in my object for the labels to print
thePrintView._currentRec=_currentRec; //pass in my object for the labels to print
thePrintView.myDataGrid.dataProvider = bedSearchEditList._recs;
thePrintView.showPage("single"); // Create a single-page image.
if(!thePrintView.myDataGrid.validNextPage) // If the print image's DataGrid can hold all the data provider's rows, add the page to the print job.
{
printJob.addObject(thePrintView,FlexPrintJobScaleType.NONE);
}
else // Otherwise, the job requires multiple pages.
{
thePrintView.showPage("first"); // Create the first page and add it to the print job.
printJob.addObject(thePrintView);
thePrintView.pageNumber++;
while(true) //queue pages
{
thePrintView.myDataGrid.nextPage(); // Move the next page of data to the top of the PrintDataGrid.
thePrintView.showPage("last"); // Try creating a last page.
if(!thePrintView.myDataGrid.validNextPage) // If the page holds the remaining data, or if the last page was completely filled by the last grid data, queue it for printing. Test if there is data for another PrintDataGrid page.
{
printJob.addObject(thePrintView,FlexPrintJobScaleType.MATCH_WIDTH); // This is the last page; queue it and exit the print loop.
break;
}
else // This is not the last page. Queue a middle page.
{
thePrintView.showPage("middle");
printJob.addObject(thePrintView,FlexPrintJobScaleType.MATCH_WIDTH);
thePrintView.pageNumber++;
}
}
}
removeElement(thePrintView);
}
printJob.send(); // Send the job to the printer.
My print view object is basically just an around my labels, then a PrintDataGrid.
If I remember correctly I fixed a similar situation in the past specifying a minHeight property to my mx:PrintDataGrid like this..
<mx:PrintDataGrid id="printViewDataGrid" width="100%" minHeight="500">
...
</mx:PrintDataGrid>
Good luck!
How can create an iframe breaking script which shows a alert box if the page is loaded in an iframe and when the alert box is clicked, it should break the frame and the script should be seen.
if (top != window) {
alert("please don't load my in a frame, thx.");
top.location.href = location.href;
}
might do the trick.