JavaScript

Moderators: None (Apply to moderate this forum)
Number of threads: 2061
Number of posts: 5164

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
How do I open a window from within a .js file? Posted by vbepicness on 6 Sept 2011 at 11:34 AM
How do I open a window from within a .js file?

I want to do this, below in a .js file like I would in a html file.

<a href="google.co.uk" class="thickbox"></a>
Report
Re: How do I open a window from within a .js file? Posted by mac_doggie on 6 Sept 2011 at 1:27 PM
In a js file you write javascript not html, so I'd say you'd do something like this:

myhtml.html
<html>
<head>
   <title>sometitle</title>
   <script type="text/javascript" src="myjsfile.js"></script>
</head>
<body>

   <a href="javascript:MyFunction("google.co.uk",1)">method 1</a>
   <a href="javascript:void(false)" onclick="MyFunction("google.co.uk",2)">method 2</a>

</body>
</html>


myjsfile.js
var win = null;
function MyFunction(url,method) {
  alert("this is method "+method);
  win = window.open(url,"popupwindow","scrollbars=1,status=1");
}


see http://www.w3schools.com/jsref/met_win_open.asp for a detailed description of the window.open function

-mac-
mailto:mac_doggie@hotmail.com
the Netherlands...
Report
This post has been deleted. Posted by mac_doggie on 6 Sept 2011 at 1:29 PM
This post has been deleted.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.