By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,574 Members | 1,535 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,574 IT Pros & Developers. It's quick & easy.

window.open not working from inside user defined function

P: n/a
Hi,

I'm trying to use window.open from inside a user defined function, and
it's not working. A code example is shown below. Thanks for any help
you can give.

Mountain Man
============

<script>

function openFootnote(contentURL) {
window.open('contentURL','footnotes','height=180,w idth=160');
}

</script>

I've tried calling on the function 2 different ways, as shown below.
Nothing happens either way.

<a href="javascript:(void)" onClick="openFootnote(fn1.html);">...</a>

<a href="javascript:(void)" onClick="return
openFootnote(fn1.html);">...</a>
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Mountain Man wrote:
Hi,

I'm trying to use window.open from inside a user defined function, and
it's not working. A code example is shown below. Thanks for any help
you can give.

Mountain Man
============

<script>

function openFootnote(contentURL) {
window.open('contentURL','footnotes','height=180,w idth=160');
}

</script>

I've tried calling on the function 2 different ways, as shown below.
Nothing happens either way.

<a href="javascript:(void)" onClick="openFootnote(fn1.html);">...</a>

<a href="javascript:(void)" onClick="return
openFootnote(fn1.html);">...</a>


Send the URL as a string, that may help.
openFootnote('fn1.html');

Regards,
Erwin Moller
Jul 20 '05 #2

P: n/a
On 26 Feb 2004 03:41:33 -0800, Mountain Man <ei*************@yahoo.com>
wrote:
I'm trying to use window.open from inside a user defined function, and
it's not working. A code example is shown below. Thanks for any help
you can give.

<script>
The type attribute is required. That should read:

<script type="text/javascript">
function openFootnote(contentURL) {
window.open('contentURL','footnotes','height=180,w idth=160');
That line passes the string 'contentURL' as the URL, not the value held by
the variable, contentURL.

window.open(contentURL,'footnotes','height=180,wid th=160');
}

</script>

I've tried calling on the function 2 different ways, as shown below.
Nothing happens either way.

<a href="javascript:(void)" onClick="openFootnote(fn1.html);">...</a>
Read the FAQ, specifically:

http://jibbering.com/faq/#FAQ4_24

The statement:

openFootnote(fn1.html);

does not do what you think it does. The browser will look for the variable
fn1, then its property, html. What you are trying to do is pass a string
literal to the function. Use:

openFootnote('fn1.html');

Also, you will want to cancel the navigation, so the intrinsic event
should read:

onclick="openFootnote('fn1.html');return false;"
<a href="javascript:(void)" onClick="return
openFootnote(fn1.html);">...</a>


As openFootnote() doesn't return a value, there is no point in adding the
return keyword.

I seriously suggest you read about the language before trying to hack away
with it. The FAQ for this group contains links and book suggestions. I
would advise you to read some of the material.

Mike
comp.lang.javascript FAQ:

http://jibbering.com/faq/

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.