Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Simple javascript window nameing question

    Hi,
    I am not a developer and apologize for this simple question/request.

    I use the following script on my website to open windows that display images:
    <script language="JavaScript">
    function SmallWindow(wintype) {
    SmallWin=window.open(wintype,"SmallWin","toolbar=no,directories=no,status=no,scrollbars=yes,menubar= no,width=650,height=500"); SmallWin.window.focus()}
    </script>
    The windows that open have no title and display the path to the image.

    1. How can I pass to the function the desired name I want to assign to the window?
    2. How can I globally assign a name to every window that is opened with this function?

    Please help.

    Thanks.

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The window name is here highlighted in red....
    SmallWin=window.open(wintype,"SmallWin","toolbar=no,....

    But it would be easier to help you if we could see how you are calling the function and exactly what names you are wanting to use. However, you could pass the name as an arguement as you did with the url. (function SmallWindow(wintype))....

    .....Willy

  • #3
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Willy,
    Here is how I call the function:
    <a href="javascript:SmallWindow('open.jpg')"></a>

    Let me clarify further:
    I would like to give the window being opend a name, similar to:
    <title>This is the window name</title>
    as used in HTML.

    Thanks.

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Since you are directly opening an image and not an html page, there's no title in the browser window. By default in IE, the full url is displayed, in Firefox the filename including image size.

    Try using the code below instead. I modified the popup image viewer script to make the title dynamic.
    Code:
    function popImg(imageURL, title) {
    	var imgWin = window.open('about:blank','imgWin','width=200, height=200, left=100, top=100');
    
    	with (imgWin.document) {
    		writeln('<html><head><title>Loading...</title>');
    		writeln('<style type="text/css"><!-- body { margin: 0px; } --></style></head>');
    		writeln('<body onload="self.focus();"><img id="pic" style="display:none" /></body></html>');
    		close();		
    		}
    	var img = new Image();
            img.onload = function() { sizeImgWin(imgWin, img, title) };
    	img.src = imageURL;
    	return false;
    }
    	
    function sizeImgWin(win, img, title) {
       	var new_w = img.width;
    	var new_h = img.height;
    	var old_w = win.innerWidth || win.document.body.offsetWidth;
    	var old_h = win.innerHeight || win.document.body.offsetHeight;
    	if (!new_w) { new_w = old_w; }
    	if (!new_h) { new_h = old_h; }
    	new_w -= old_w; new_h -= old_h;
    	win.resizeBy(new_w,new_h);
    	win.document.title = (title) ? title:img.src.substring(img.src.lastIndexOf("/")+1);
    	var pic = win.document.getElementById('pic');
    	pic.src = img.src;
    	pic.style.display = 'block';
    }
    You would use it this way:

    <a href="open.jpg" onclick="return popImg(this.href, 'This is the open image')"></a>

  • #5
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Glenn,
    Quite clever and thanks for this script.

    You wrote:
    Since you are directly opening an image and not an html page, there's no title in the browser window. By default in IE, the full url is displayed, in Firefox the filename including image size.
    So, is there any way to change the default way IE behaves? Is there a way to place a title instead of the full URL?

    Thanks.

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Why are you still insisting on your original implementation which can't be done? The script I posted already solves this problem.

  • #7
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by glenngv
    Why are you still insisting on your original implementation which can't be done? The script I posted already solves this problem.
    Glenn,
    You gave me fine alternative but I need a solution addressing the original script because it is embedded in many HTML pages I use. I could easily alter the original script with a batch search and replace.

    You said: your original implementation which can't be done. So, are you declaring that the title problem can not be programmatically solved, with the original script calling an image?

    Thanks.

  • #8
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Spinacia
    So, are you declaring that the title problem can not be programmatically solved, with the original script calling an image?
    That's exactly what he said....

    Quote Originally Posted by Spinacia
    I could easily alter the original script with a batch search and replace.
    If you can use a batch search and replace to modify part of your original function, why can't you do the same to replace the entire function with the new function?

    Also, you are incorrectly using the anchor to call your function and thus making your links inaccessable to users whom have javascript disabled. This too, should also be addressed....

    .....Willy

  • #9
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Willy Duitt
    That's exactly what he said....
    I guess you agree with him...


    If you can use a batch search and replace to modify part of your original function, why can't you do the same to replace the entire function with the new function?
    I could replace a function, but not introduce a full script. I don't have the tools to do multiple-line search and replace.

    In any case, thanks for the help.

  • #10
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Put the code I posted in an external file, name it as popimage.js. Then just include it in your pages that need that script.

    <script type="text/javascript" src="popimage.js"></script>

  • #11
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by glenngv
    Put the code I posted in an external file, name it as popimage.js. Then just include it in your pages that need that script.

    <script type="text/javascript" src="popimage.js"></script>
    That's the best idea by far and also feasible. Thanks.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •