www.webdeveloper.com
Results 1 to 3 of 3

Thread: Setting location.href on a modal popup opens a new window

Hybrid View

  1. #1
    Join Date
    Sep 2010
    Posts
    2

    Setting location.href on a modal popup opens a new window

    Hello,

    I am developing an application that is opened via a modal popup from another application that I do not have control over. In IE, the method of creating the popup that holds my application is window.showModalDialog. When I redirect the user via javascript with something as simple as, location.href='someURL'; another popup window is opened rather than just redirecting the browser.

    When a user is using anything other than IE, the window.open method is used and those browsers redirect within the same window appropriately.

    I have mocked up a very basic sample.
    main.html is the external application.
    popup.html is my application.
    redirect.html is the page I need to redirect to within my application.

    main.html:
    HTML Code:
    <html>
    	<head>
    		<script language="javascript">
    			function OpenPopup()
    			{
    				if (window.showModalDialog) {
    			            window.showModalDialog("popup.html","mywindow",
    			            "dialogWidth:1024px;dialogHeight:768px");
    			        } else {
    			            mywindow= window.open ("popup.html", "mywindow","menubar=0,toolbar=0,location=0,resizable=1,status=1,scrollbars=1,width=1024px,height=768px");
    			            mywindow.moveTo(300,300);
    			            if (window.focus)
    			                mywindow.focus();
    				}  
    
    			}
    		</script>
    	</head>
    	<body>
    		<a href="#" onclick="OpenPopup()">click</a>
    	</body>
    </html>
    popup.html:
    HTML Code:
    <html>
        <head>
            <script language="javascript">
                function Redirect()
                {
                    location.href = "redirect.html";
                }
            </script>
        </head>
        <body>
            <a href="#" onclick="Redirect()">redirect</a>
        </body>
    </html>    
    redirect.html:
    HTML Code:
    <html>
    	<body>
    		redirected
    	</body>
    </html>

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    <html>
        <head>
        <base target="_self">
            <script type="text/javascript">
                function Redirect()
                {
                document.getElementById('foo').href = "redirect.html";
                document.getElementById('foo').click(); 
                }
            </script>
        </head>
        <body>
            <a id="foo" href="#" onclick="Redirect();">redirect</a>
        </body>
    </html>
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    Sep 2010
    Posts
    2
    Hello Fang,

    Thank you very much for your response. Your example fixed the mockup that I had written perfectly.

    Regrettably, I had to go with a completely different approach because even with this fix, I had a problem redirecting across domain boundaries (just my assumption)

    If I change main.html to open something that I was hosting with IIS (e.g. http://localhost/UI/popup.html) it would still open a third window.

    I ended up scrapping the redirect and just blanketing the whole screen with a div with a high z-index. All I really needed to do was log the user out and then notify them that I had done so in the background.

    Regards,
    bizzarry

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles