I have made a window, with a couple of buttons. When I click them, I have a function which fires up. Now my question is how can I change the (same) window to show another html file? I have tried
function callback(a) {
curr_window = a.contentWindow.location;
{
as a callback to the window.create function, and
click_Function(){
curr_window.assign("html file");
}
in a
<script></script>
inside the HTML file, but that didn't work because (from my googling) main.js isn't executed in the page, so their global variables aren't shared. So how can I change the window's location using the onClick function?
You are not supposed to be able to directly change a window's location in a Chrome App. The only part of the location object you can change is the href to reference a fragment in a document.
This was an explicit design decision of the Chrome Apps team to stop apps from having the flash of white whilst it navigates between pages. If you look at the window api the only method is create and that takes the URL of what that window should display.
That being said, you can load an iframe in the main window and change that. You would just need to set the iframe to be 100% of the width and height of the window.
Related
Here is the situation: I am building a chrome extension that injects a sidebar to a page (simple HTML) when the browser icon is clicked. I also use message passing to check if the button was already clicked for a domain name so that I automatically (re)display the sidebar.
I am wondering if it is possible to intercept the loading of the page content so that my sidebar loads first, then the actual page.
If you inject at "document_start", your code executes before any DOM is constructed.
You can then, for instance, hook a DOM Mutation Observer to watch for some kind of parent node to be inserted, say <body>, and add your UI then.
I'm working on a project which insists on using real modal windows. The current implementation works, it simply calls "showModalDialog" and uses the result that the dialog stores in "returnVal".
However, on Chrome, when you navigate to a different page, this functionality no longer works. It's a documented bug.
I'm changing it to use window.open. I can pass in a callback no problem... However, the popup window needs to be navigatable (it's to add an item to a DB, then return the items ID to the calling page). I can pass the callback in to the popup window, but when it navigates, I lose that callback...
Is there any way I can keep a pointer to a callback even when navigating to a new page in a popup window?
Open a frameset in the dialog, and in the frameset load the page in a frame.
When you navigate to the next page, it will be inside the frame, so the frameset stays the same and the returnVal is intact. You can access the return value using parent.returnVal from the frame.
can browser popout windows be launched (like google talk conversation windows can be popped out into a new window from the main gmail page.) so they are still part of the main page i.e. share resources and access and modify each other, e.g. if the popout window contained a button it can be clicked and modify part of the original page without having to go to the server? I'm guessing the answer is no, but as I don't know for sure I thought I'd ask.
You can access the popout parent by using the window.opener property from within the 'popout' window. That will give you the window object of the parent.
So if on your main page you have a global variable test
var test = 'Hello';
It can be accessed from the child window using
window.opener.test
I have created a simple webpage that launches a widget after a button is pressed. The button press adds an element to the DOM tree:
var div = document.getElementById("loginWidget");
var loginWidget = document.createElement('script');
loginWidget.setAttribute("type", "text/javascript");
loginWidget.setAttribute("src", "http://widgetstore.etc.etc");
div.appendChild(loginWidget);
This launches the login widget in the webpage. How do I get it to open in a new window (preferably resized to the size of the widget? If I do it like this will my original window be able to access values from the login widget? If this is a bad idea what's the best way to style the widget so it stands out more from the original size.
Forgive my n00bness. Would normally research this myself but in a bit of a hurry!
Take a look at window.open. It will return a pointer to newly opened window. And you can specify a width and height of that window. But note that you must call window.open in onclick handler. Otherwise, if you will call it in your script block it will be blocked by browser.
Also, from widget window you can access initial window using window.parent.
I am working on a java webapp that is displayed in an iframe inside a larger portal.
My webapp must always be inside the iframe of the outer portal, but when the user right clicks on one of my webapp's links and does "open in new window/tab", he sees my webapp as a standalone website in the new window.
How do I prevent seeing my app outside of the portal's iframe?
The functionality you're referring to is at the browser level and is therefore impossible to remove (i.e., the link option will always be there). There are several things you can do to ensure that your app is running inside a frame:
Check for the presence of a frame:
if (top === self) { not in a frame } else { in a frame }
Disable the right click menu (ctrl + click will still work) Below is a simple example.
<body oncontextmenu="return false;">
Note: Although I'm sure it goes without saying, if the user has disabled JavaScript, this approach will not work.
Check window.parent on load.
With javascript you can detect if you are running inside an iframe. Look: How to identify if a webpage is being loaded inside an iframe or directly into the browser window?