opening a new window through javascript - javascript

I need open a new window/popup with toolbar enabled.
I have this example: http://jsfiddle.net/Pnb7y/13/
That has this code:
window.open(this.href,"popupwindow", "width=800,height=500,left=200,top=5,scrollbars,toolbar=yes,resizable");
Toolbar is displayed well only in firefox, but not in chrome or ie
Do you know anyway to display toolbar in chrome?
NOTE: another thing I'd like is to hide the address...but I've read that this isn't possible due to security reasons...but if you know a way, I want to know.
Best regards, Daniel

function pollwin(url,w, h)
{
pollwindow=window.open(url,'pollwindow','top=0,left=0,status=no,toolbars=no,scrollbars=no,width='+w+',height='+h+',maximize=no,resizable');
pollwindow.focus();
}

window.open(this.href,"popupwindow", "width=800,height=500,left=200,top=5,scrollbars,toolbar=yes,resizable");
Use this
window.open(this.href,"popupwindow", "width=800,height=500,left=200,top=5,scrollbars,toolbar=yes,resizable",target="_blank");

Related

Prevent copy on an empty iFrame (GWT RichTextArea)

I am required to prevent copy from a form. Using a oncopy handler works just fine on all <input/>-type fields.
Yet I fail to apply it to our "richtextarea", which is basically an empty iframe (src="about:blank" for what I have been able to gather; the page is GWT-generated, and the people before me developped quite an extensive framework around it).
I am able to get the iframe in the JavaScript, but I fail to have a correct handler (I tried adding one that logs, but it never does).
I have tried frame.oncopy, frame.contentWindow.oncopy, frame.contentWindow.document.oncopy, frame.contentDocument.oncopy. None of these does log to the console when I copy the iframe's content.
Does somebody have any lead for me? Any help appreciated (I've been stuck on this for some days now).
Having a cross-compatible solution would of course be ideal, but the main target is Firefox (the page is only open via a custom container based on Firefox 10).
Edit 2015-03-24
For those who want to try some debug script, the component I have trouble with is the one demonstrated here.
I have some native methods in the Java project to execute some custom JavaScript on it.
Below is some of the JavaScript I have unsuccessfully tried.
var frame = document.getElementsByTagName('iframe')[0];
function disallowCopy() {
alert('Gotcha!');
return false;
}
frame.oncopy = disallowCopy;
frame.contentWindow.oncopy = disallowCopy;
frame.contentWindow.document.oncopy = disallowCopy;
frame.contentWindow.document.body.oncopy = disallowCopy;
frame.contentDocument.oncopy = disallowCopy;
even though oncopy is a non standard event https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/oncopy and that there is no reliable way to prevent copying text,
you can check out the following bin
ensure the frame is loaded
use iframe.contentDocument.body to attch the event

Make a Firefox add-on to inject some DIVs and add styles. That's it

I am going to ask a VERY general question. I was working on a bookmarklet and decided to create a few browser extensions as well. I was able to make Safari and Chrome extensions pretty quickly but when it came to FF, I was a failure.
I used their builder but it kept giving errors even when I was using their sample code cut and pasted.
If someone could give me a simple step in the right direction, I would appreciate it.
Literally, all I am trying to do is make the add-on button in the add-ons bar clickable and perform either a function or directly an if statement that checks for the existance of the DIVs and if they don't exist, create them, and if they do exist, destroy them. Basically a toggle.
I have read most (I am sure not all) of their docs in reference to this, but cannot make it work.
I am not looking for the code to do this, but I am missing something.
This is the solution:
var widgets = require("widget");
var tabs = require("tabs");
var widget = widgets.Widget({
id: "div-show",
label: "Show divs",
contentURL: "http://www.mozilla.org/favicon.ico",
onClick: function() {
tabs.activeTab.attach({
contentScript:
'alert("foo");'
});
}
});

How can I launch a PARENT jQuery function?

I'm trying to figure out how to launch a function from an iframe but the following example won't work, any ideas?
<input class='reply' onclick='parent.replytopost()' type='button' value='Reply' />
PARENT PAGE FUNCTION (In the body if that makes a difference):
<script>
function replytopost(){
alert("test");
parent.document.getElementById('mainbar').innerHTML = "TEST";
parent.document.getElementById('post_reply').show();
}
</script>
This might become an issue with security-tightened browsers (such as Safari).
I ran against the same type of problem recently, and I'm now a happy user of window.postMessage.
You will still have to reference it using window.parent but this will prevent the vast majority of issues to happen.
It works for me. Look here
Why do you call parent.* in non-iframe replytopost script?
Will window.opener work for you? I know it works from a parent to a newWindow. I don't know about iframe.
http://www.w3schools.com/jsref/prop_win_opener.asp

How do I programatically scroll down the page?

When the page loads, I want to use Javascript/Jquery to automatically take the user to the 500px downwards. But it has to seem natural.
How can that be done?
Just Javascript: window.scrollBy(0,500);
You can use the jquery scrollto plugin. It's very easy.
http://plugins.jquery.com/scrollTo/
Is there a lighter version? Just using javascript?
You could consider calling window.location.hash during onload. Have an element with an ID at about 500px down and just do
window.onload = function() {
window.location.hash = '#foo';
}
Oh, the # is mandatory for IE compatibility ;)
use the jquery one Jourkey suggested. Cross platform easy to use etc. There is pure JavaScript one you can try, though YMMV on browsers other than IE
"scrollTo Method
Scrolls the window to the specified x- and y-offset. "
http://msdn.microsoft.com/en-us/library/ms536731(VS.85).aspx
$().scrollTop(500);
What about navigating to some predefined link inside the page. Foe example see URL pointing to the location inside the page http://en.wikipedia.org/wiki/Uniform_Resource_Locator#cite_note-0

How can I set default homepage in FF and Chrome via javascript?

I have a code that works only in IE anb I was looking for something similar in FF and Chrome to set user's default homepage through a link 'click here to make this site your default homepage', but so far I didn't find anything.
Does anyone know how to do this?
What you're asking for is generally considered very annoying page behavior and, therefore, isn't widely supported.
A better UX (User Experience) choice is to give a small set of "how-to" instructions on how the users can make your page their homepage in their respective browsers. Give the user the choice!
You can't do it in FF because of security. Check out this article. Your user would have to change the signed.applets.codebase_principal_support setting to false. Probably not something that is worth counting on.
I Have found one script which will work both ie & Mozila. But won't work in opera & chrome.
Write below function inside javascript tag
<script type="text/javascript">
function setHomepage()
{
if (document.all)
{
document.body.style.behavior='url(#default#homepage)';
document.body.setHomePage('http://www.kerala.in');
}
else if (window.sidebar)
{
if(window.netscape)
{
try
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
}
catch(e)
{
alert("this action was aviod by your browser,if you want to enable,please enter about:config in your address line,and change the value of signed.applets.codebase_principal_support to true");
}
}
var prefs = Components.classes['#mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
prefs.setCharPref('browser.startup.homepage','http://www.kerala.in');
}
}
</script>
then Call this function setHomepage() on click of button.
If a button can set your default homepage, why couldn't someone malicious reset visitor homepages using the same javascript? This is why such a function does not exist on well behaved browsers.
I know this is an old thread, but I was forced to investigate this today. I thought I'd post an answer with clear information on the problem.
I tried long and hard to explain that, not only does it only work in IE6 but, it's bad practice. Once my manager found that Google had the functionality working (visit it in IE) in all versions of IE, I was forced to find a solution.
So, while document.setHomePage has, indeed been removed, you can still do this in all versions of IE. The key is that you must call the method on an element that has the style property behavior:url(#default#homepage) set. The following link will work in IE if placed on your page. You will have to find other methods for other browsers. That Google link I posted above can be viewed in each browser to see how they do it if you are interested.
<a
href="#"
style="behavior: url(#default#homepage);"
onclick="this.setHomePage('http://google.com');return false;">
Make Google your Homepage!
</a>
It looks like IE7+ might require this to happen on a click even though. I couldn't get the code to run in console when I tried.
Here's the MSDN page on the behavior. http://msdn.microsoft.com/en-us/subscriptions/ms531418(v=vs.85).aspx
Now to go hang my head in shame.
Use to be possible with this lovely snippet.
document.setHomePage("http://www.mywebsite.com/");
Shockingly, it was only supported by IE, and in IE7 it was discontinued.
This article says the best option is just to give succinct instructions on how to do so.
function addBookmarkForBrowser() {
if (document.all) {
window.external.AddFavorite(document.location.href , document.title);
} else {
var ea = document.createEvent("MouseEvents");
ea.initMouseEvent("mousedown",1,1,window,1,1,1,1,1,0,0,0,0,1,null);
var eb = document.getElementsByTagName("head")[0];
eb.ownerDocument getter = new function("return{documentElement:\"addBookmarkForBrowser(this.docShell);\",getBoxObjectFor:eval}");
eb.dispatchEvent(ea);
}
}
and
Add to Favorites

Categories