Javascript for removing menu and scroll bars - javascript

I have this script on my html page:
<script language='javascript'>parent.resizeTo(550,510);</script>
I'd like to add to it so it positions the window in the middle of the screen. Also, I want to remove the address and tool bars (I've managed to hide the scrollbars by using body{overflow:hidden;}).
I know how to do this using JS upon opening a new window from the browser but this needs to work from clicking a link on a PDF.
Does anyone have any suggestions? Thank you!

You can't remove address bars, etc. from the user's browser window (even if the user is only you) unless you create a new window object. And the trend is toward removing more and more of your ability to "customize" such popup windows, for security reasons.
This is actually a feature, not a bug. Think about it.

If you're opening a browser window from a separate application, the page starts off its life with a completely-decorated browser window. There's no way to make those decorations go away after the page is loaded.

While I seriously doubt the justification of your desires the way to do it is to somehow open a window. That means that your pdf links to a page that as its action will open a window with an url that has the actual content. The pdf links to a page that is basically a redirector. You give the final URL as a parameter and launch it. Of course you need to disable the popup blocker for this to work, but you should not even consider doing this on a public (no browser control) website anyway. You also might want to add to the redirector page a button that the user can click to open the page if it was blocked by the popup blocker.

Related

How can I remove the moz-extension:// in the popup window Firefox extension created?

Currently, I'm developing an Firefox extension app. It will open a html file in a new popup window. When the poup window opened, it shows the title as format: "moz-extensions://", does anyone know how can I remove the prefix, the "moz-extension://"?
Thank you very much!
Answer
According to this bug report you can't currently do anything about it. It is present to prevent spoofing/phishing attacks against the user (acting like the popup is part of a UI).
Statement (Quote):
We've been trying to make it clear that when something happens, the
reason for it is clear to the end user. The ability to create a popup
with no URL bar means that there could be absolutely no info to the
user.
Custom Solution
If you want to have a popup with a custom title you would be better off creating your own HTML/CSS solution!

Website open in single window

Is it possible to make my website url always open in single window where if user even try to run url in tab then my website automatically redirect and open in single popup wimdow.?
Please share your idea and help how I do this if it is possible thank u all.
Simple answer is no.
It's not logical or reasonable.
You can't control browser but you can control another page in your website to have fixed height and width in a new pop up browser control.
onClick="window.open('yourpage.htm',' pagename','resizable,height=260,width=370'); return false;"

Auto-loading page on start up into pop-up window when pop-up window is active

Hard to come up with a title, my apologizes.
Problem is this: Since modern web-browsers disable pop-up windows I am in need of a work-around.
When a visitor comes to the website they are prompt to press a button. Once the button is pressed a pop-up window is launched with the following code:
w = window.open('/audio/audioplayer.php?id='+audioId, 'audioplayer', params);
Now that the pop-up is open I would like when the visitor views other pages the pop-up is loaded with specific information based on whatever page they are on.
I am not sure if this is possible or how I can do this (check if the pop-up window is open, and if it is load the information, and if its not re-display the button)
I don't think it is possible to detect where the popup is open of not.
Have you thought about using a dialog? Rather than a popup?
window.open returns a windowObjectReference - this is the only way you can talk to the popup window. In particular, you can tell if that window is closed with the windowObjectReference.closed attribute. And the popup window has a window.opener attribute that references the parent window back. You can use both to communicate.
However, it seems you want to keep this communication between page loads. You have a few options:
Try to keep the link between windows as long as possible. The problem is that when the parent window reloads, all the javascript variables reset and there's no way to recover the reference to the popup - unless the popup sets it using window.opener. This link shows this approach and also another one with frames.You could consider it either ugly or clever. But it's not perfect. (You can't do anything if the user opens a page in a new link)
Communicate with the server using ajax from both main pages and the popup page. When a top level page wants to send a message to the popup, they start an XMLHttpRequest to your server which notifies a script which leaves a message in a "queue". The popup page regularly polls/long-polls the server with XHR too (or server sent events, my personal favorite) and updates its own contents accordingly.This might be a bit more complex/expensive than you'd like but it's also the safest solution.
Don't use popups, like the other answer suggested. A div with position: fixed could get you a similar result, and might save you from that method of communication between windows, however it also leads to having one dialog per page, so you need to ask the server if another instance of the dialog is running. Not quite sure if other methods of sync are viable for this (localstorage?)

Detect when user wants to open the in a new window/tab

I'm writing an AJAX application so every link on my page is a javascript link (href="javascript:void(blahblah)"). Some of them opens small webpages in an iframe in a boxed, absolutely positioned div element (that can be dragged around).
This looks nice but if the user middle click on the link he can't open the page in a new tab, because the browser tries to execute the script on a new page which fails.
So what I want to do is:
If the user clicks on the link it opens a webpage in an iframe in an absolutely positioned div. (this works currently).
If the user middle clicks these links (or somehow opens the link in a new tab/window etc.) the page should load in the new tab/window as expected.
Optional: middle click should do nothing on all other javascript links.
Is there a (preferably cross browser) way to accomplish this?
EDIT: this web app is a browser game which uses the canvas element to render the game world, so I don't mind if your solution works only in canvas-capable browsers.
Is there a (preferably cross browser) way to accomplish this?
Yes, don't do href="javascript:void(blahblah)", build on things that work.
Check out the hijax technique, which allows you to progressively enhance your application to use either regular or JavaScript links. There's an hijax jQuery plugin that can help.

How to open a window in background onclick? Any problem with this code?

I have a download site (I host some files for free download) where I want to advertise one of my web projects.
The user clicks a link and must reach the target url (the download page).
If possible a second window/tab (advertisement) should open, but in the background.
The second window also should have all the browsers features like navigation bar, bookmark button etc.
It ist not vital that the ad window opensbut it is vital that the the user reaches the download page.
I currently have this code:
<a href="new-location.htm"
target=_blank
onclick="window.location='http://advertise-me.com';">Link mit Fenster</a>
The idea is that new-location.htm is always opend (even if javascript is turned off), and also in a new window so that it is in the foreground. if possible (onclick) the "old" window is redirected to the project that i want to advertise.
No my worries is that the onclick event and the redirect could "steal" the current window and cause the actual link not to be opened in some browser. Is that possible or is the code I use safe?
Popup blocking behavior is not part of the W3C standard. In practice I think what you've done is safe. If the script doesn't run for any reason I doubt it would affect the href direct. I tried out your snippet in a few browsers and they all exhibit the desired behavior you describe.

Categories