PDA

View Full Version : Microsoft Script Editor help



hewston
Dec 15th, 2008, 04:34 PM
Hi,
I'm pretty much a complete newbie to code, and have been working on some pages for my work. Unfortunately my work has no dedicated html program like Frontpage, etc so I am having to use MS Word as my editor (!). I've managed to put together some good pages, but the code is extremely basic.

I'm now trying to add some javascript for opening a new window, and have read a few help files and tutorials, etc but am now stuck. It looks like the limitations of Microsoft Script Editor is the problem, but can someone help me out please..

This is the code I'm currently trying to insert based on a couple of tutorials I've read:

---Function in header:
<script language="javascript">
function open_win(url_add){window.open(url_add,'welcome','width=300,height=200,menubar=no,status=no,location= no,toolbar=no,scrollbars=no);}
</script>

---Calling function in body:
<A HREF="javascript:void(0)" onclick="open_win('http://www.hotmail.com')">Go to hotmail</A>

As far as I can tell from the tutorials, this should open hotmail in a new window.

When I insert the hyperlink, the code is automatically adjusted to read as follows: <A HREF="javascript:void(0)">


Can someone please tell me what I'm doing wrong - is it me, or the editor, or both?

Any help would be great.

Thanks.

Rowsdower!
Dec 15th, 2008, 04:52 PM
Hi Hewston, welcome to the forums. My first question is why you are using Java for this. You can open a link in a new window by adding target="_blank" to the <a> tag and you won't have any issues with viewers who have disabled their Java.

See here:
http://www.w3schools.com/TAGS/att_a_target.asp

Are you trying to do something other than open certain links in a new window (eg. pop-up ads or similar)? If not, stick with the target="_blank" approach. :thumbsup:

BoldUlysses
Dec 15th, 2008, 04:52 PM
Mac/Linux user here, so I can't really comment on your struggles with MS Word (yikes!); however, you might consider downloading a free, dedicated HTML editor like Notepad++ (http://notepad-plus.sourceforge.net/uk/site.htm).

hewston
Dec 15th, 2008, 04:55 PM
Hi Hewston, welcome to the forums. My first question is why you are using Java for this. You can open a link in a new window by adding target="_blank" to the <a> tag and you won't have any issues with viewers who have disabled their Java.

See here:
http://www.w3schools.com/TAGS/att_a_target.asp

Are you trying to do something other than open certain links in a new window (eg. pop-up ads or similar)? If not, stick with the target="_blank" approach. :thumbsup:

Hi, thanks.

Thanks Rowsdower, I'll definitely check out this option - the reason I went straight to java was because I wanted to be able to set window size with noresize config - the window I intend to open with the code is about quarter size of a normal page.

Is there any other way around this?

BoldUlysses
Dec 15th, 2008, 05:07 PM
the reason I went straight to java was because I wanted to be able to set window size with noresize config - the window I intend to open with the code is about quarter size of a normal page.

Javascript is really your only option here; there's no way to do it with pure HTML/CSS.

Before you progress further, you might also consider this (http://www.useit.com/alertbox/990530.html) and this (http://www.sitepoint.com/article/beware-opening-links-new-window/)

Rowsdower!
Dec 15th, 2008, 05:09 PM
Ah, well if you want to control the browser window that the new page opens up in I think Java will be your only option. Off-hand I've never really bothered to implement this but I'm sure there are countless tutorials.

Here's another one to review:
http://www.w3schools.com/JS/tryit.asp?filename=tryjs_openallwindow

I'll try to digest this and see where your code runs astray... More to come unless someone beats me to the punch.

Rowsdower!
Dec 15th, 2008, 05:12 PM
Actually, based on the code right there I don't even need to learn. Try this:


<html>
<head>
<script type="text/javascript">
function open_win()
{
window.open("http://www.hotmail.com","_blank","toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=400, height=400");
}
</script>
</head>

<body>
<form>
<input type="button" value="Open Window" onclick="open_win()">
</form>
</body>

</html>


It worked on the test page at W3 schools... Just change the features (scroll bar, etc.) that you want to control and you're done.

hewston
Dec 15th, 2008, 05:12 PM
Ah, well if you want to control the browser window that the new page opens up in I think Java will be your only option. Off-hand I've never really bothered to implement this but I'm sure there are countless tutorials.

Here's another one to review:
http://www.w3schools.com/JS/tryit.asp?filename=tryjs_openallwindow

I'll try to digest this and see where your code runs astray... More to come unless someone beats me to the punch.

Cheers mate. I should also mention that there's going to be several links on the same page with different urls that I want this code attached to. My original code tried to use the var function to accomplish this.

Rowsdower!
Dec 15th, 2008, 05:19 PM
Not going to let me off easy, eh?

Well then you can try this:


<html>
<head>
<script type="text/javascript">
function open_win(linky)
{
window.open(linky,"_blank","toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=400, height=400");
}
</script>
</head>

<body>
<form>
<input type="button" value="Open Window" onclick="open_win('http://www.hotmail.com')" >
</form>
</body>

</html>Then just enter the individual links in the red area for each link. If you don't like the button look you can use CSS to style them to look just like regular links anyway, too.

Let me know if I botched the code at all...

Rowsdower!
Dec 15th, 2008, 05:21 PM
Not going to let me off easy, eh?

...Then just enter the individual links in the red area for each link. If you don't like the button look you can use CSS to style them to look just like regular links anyway, too.

Let me know if I botched the code at all...

I suppose I might need to clarify, but I mean to say that you would of course have a separate <input> item for each link and the part in red is all that you would need to change.

hewston
Dec 15th, 2008, 05:22 PM
Thanks, but you've lost me with CSS - I have no clue where to start with something like that. Can it be done as a hyperlink?

Rowsdower!
Dec 15th, 2008, 05:25 PM
Probably, but that will take some more thinking for me.

As for CSS, it's not as intimidating as it first seems once you start to learn. It comes in very handy and gives your pages a much more professional look so if you don't already know how to use CSS, make this a priority.

Rowsdower!
Dec 15th, 2008, 05:35 PM
Ok, how about this?


<html>
<head>
<script type="text/javascript">
function open_win(linky)
{
window.open(linky,"_blank","toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=400, height=400");
}
</script>
</head>

<body>
<a href="#" onclick="open_win('http://www.hotmail.com')">regular link text</a>
</body>

</html>
Again, you're changing only red text areas above.