Set zoom level on a new internet explorer child window - javascript

I have the below code which launches the page and sets the zoom to 175%. I would like to do this for the w3schools link below...e.g. in a child window if anyone knows how. thanks .
IE 8 compatible, dont care about other browsers at the moment.
<html>
<head>
<title>olecmdid</title>
<script>
function zoom(percent) {
var PROMPT = 1; // 1 PROMPT & 2 DONT PROMPT USER
var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
var status = WebBrowser1.QueryStatusWB(63);
document.getElementById("QueryStatusWB_Result").innerHTML = status;
WebBrowser1.ExecWB(63,PROMPT,percent,null);
WebBrowser1.outerHTML = "";
}
</script>
</head>
<body onload="zoom(175);">
<form name="form">
<input type="Button" value="25%" onclick="zoom(25);">
<input type="Button" value="50%" onclick="zoom(50);">
<input type="Button" value="100%" onclick="zoom(100);">
<input type="Button" value="150%" onclick="zoom(150);">
<input type="Button" value="200%" onclick="zoom(200);">
</form>
Visit W3Schools.com!
</body>
</html>

I managed to get a workable solution for what I needed. So I resize the existing window and then launch a new window and then go back and resize the original window. Might help someone else.
<html>
<head>
<meta http-equiv="x-ua-compatible" content="IE=10">
<script>
function openwind() {
zoom(400);
var purchaseWin = window.open("test.html", "Google", "width=600, height=600");
setTimeout(function(){
zoom(100);
}, 500);
}
function zoom(percent) {
document.getElementById('WebBrowser1').ExecWB(63,2,percent,null);
}
</script>
</head>
<body>
<input type="button" value="Open window 400% Zoomed" onclick="openwind()">
<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>
</body>
</html>

Related

Move a popup window using setInterval() in javascript

I'm trying to make a window pops up and then moves continuously using setInterval(). It pops up but it doesn't move.
I'm using all the html files in the same directory.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>popup</title>
</head>
<body>
<input type="button" name="" value="new window" onclick="newWin();">
<input type="button" name="" value="stop window" onclick="stopWin()">
<script type="text/javascript">
var win1;
var interv;
function moveWin(){
win1.moveBy(100, 100);
win1.focus();
}
function newWin(){
win1 = window.open('new.html', 'win1', 'width=200, height=150');
win1.focus();
interv = setInterval(moveWin, 1000);
}
function stopWin(){
clearInterval(interv);
}
</script>
</body>
</html>

Force a link in I.E. to open in Firefox

I have two links in a corporate intranet site, built in Sharepoint, that I need to link to Firefox. The links are to an external site that does not work in I.E. However, the corporate browser is I.E., so that's what most people see.
I found the below code that works when I have one link. How do I get it to work for two links?
Here's the code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>HTA Test</title>
<hta:application applicationname="HTA Test" scroll="yes" singleinstance="yes">
<script type="text/javascript">
function openURL()
{
var shell = new ActiveXObject("WScript.Shell");
shell.run("http://www.google.com");
}
</script>
</head>
<body>
<input type="button" onclick="openURL()" value="Open Google">
</body>
</html>
You can modify your script to something like:
<script type="text/javascript">
function openURL(url)
{
var shell = new ActiveXObject("WScript.Shell");
shell.run(url);
}
</script>
</head>
<body>
<input type="button" onclick="openURL('http://www.google.com')" value="Open Google">
<input type="button" onclick="openURL('http://www.yahoo.com')" value="Open Yahoo">

How to open a url in a text box in a separate frame?

I'm working on a webpage that will consist of a large main frame, with a small frame across the bottom with a text box and submit button. I need the submit button to change the main frame to the url in the text box. My code is below, but it only works if the url ends in a file name (e.g., index.htm). It won't work if the url ends in .com or /folder/ where index.htm is assumed. How can I fix it?
Here is my html/javascript. In my index.htm I have:
<html>
<head>
<title>Menu Bar</title>
</head>
<frameset rows="*,30">
<frame src="main.html" name="main" id="main">
<frame src="menu.html" name="menu" id="menu">
</frameset>
<body>
</body>
</html>
The main.html is basically a blank html document (it has basic html, head, and body formatting only).
Here is menu.html:
<html>
<head>
<script language="JavaScript">
function go(){
URL = document.myForm.theURL.value;
parent.main.location=URL;
}
</script>
</head>
<body>
<form name="myForm">
<input type="text" name="theURL" size="50">
<input type="button" value="Go" onClick="go()">
</form>
</body>
</html>
I'm not sure why this happens, but you can use this workaround:
function go(){
var URL = document.getElementById('myForm').theURL.value;
if (URL) {
url = URL.split('/');
if (url[url.length - 1].indexOf('index.htm') < 0) {
url[url.length] = 'index.htm';
URL = url.join('/');
}
} else {return;}
parent.main.location.href = URL;
// or: parent.main.contentWindow.location.href = URL;
}
To use this, you need to set id="myForm" to form element.

How to redirect parent page using javascript

I want to ask you how to redirect parent page to a certain url from a pup up page? I tried several options as parent or opener and nothing is working. Please help me to understand what is wrong.
here is the code i used:
<html>
<head>
<script>
function openWin(){
myWindow=window.open('','','width=200,height=100');
myWindow.document.write("<p>This is 'myWindow'</p> <button onclick=\"window.opener.location.href = ='http://www.google.com'; window.close();\">refresh</button>");
myWindow.focus();
}
</script>
</head>
<body>
<input type="button" value="Open window" onclick="openWin()" />
</body>
</html>
You have an error in your code. Should be
myWindow.document.write("<p>This is 'myWindow'</p> <button onclick=\"window.opener.location.href = 'http://www.google.com'; window.close();\">refresh</button>");
i.e., remove the extra = before 'http://www.google.com'.

Newbie: hanging browser on function call

I just started learning JavaScript and am wondering why this simple snippet hangs when I click on the "Call function" button. What am I missing?
<html>
<head>
<script type="text/javascript">
function myfunction()
{
document.write("hello");
}
</script>
</head>
<body>
<form>
<input type="button"
onclick="myfunction()"
value="Call function">
</form>
</body>
</html>
You need to write inside an element or give an element a value, or you should use document write like that :
<html>
<head>
<script type="text/javascript">
function myfunction()
{
document.getElementById("lblMessage").innerText = "hello";
document.getElementById("txtMessage").value = "hello";
//document.write("hello");
}
</script>
</head>
<body>
<form>
<script type="text/javascript">
document.write("This is written while page processed by browser !<br />");
</script>
<input type="text" id="txtMessage" /><br />
<span id="lblMessage"></span><br />
<input type="button"
onclick="myfunction()"
value="Call function">
</form>
</body>
</html>
If you simply want to see your button doing something then try:
alert("Hello");
instead of the document.write.
Where do you expect the function to output its "hello"? Right into the button's source code? That makes no sense. The browser is confused and hangs.
Document.write doesn't magically insert something at the end of your document. It writes its stuff out right there where it is called.
Not too sure what you mean by "hang"... Try this out... The alerts can be removed, but will inform you of where it is at in execution...
<html>
<head>
<script type="text/javascript">
function myFunction() {
//for debugging
alert('Made it into function');
document.getElementById('MyOutputDiv').innerHTML = 'Word To Your Mom...';
//for debugging
alert('function complete');
}
</script>
</head>
<body>
<input type='button' onclick='myFunction();' value='Call Function'>
<br>
<div id='MyOutputDiv'></div>
</body>
</html>
document.write, but where? You have to specify this.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Hello</title>
</head>
<body>
<pre><script type="text/javascript">
function myfunction() {
d = document.getElementById('hello');
d.style.display = "block";
d = document.getElementById('callme');
d.style.display = "none";
}
</script>
</pre>
<div id="hello" style="display:none">
Hello
</div>
<div id="callme">
<input type="button"
onclick="myfunction()"
value="Call function">
</input>
</div>
</body>
</html>
I can't explain the "hang" but please take a look at this page for a primer on document.write: http://javascript.about.com/library/blwrite.htm I would also like to second that you probably want to write to a specific element in the page rather than just overwriting the entire page.

Categories

Resources