Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window.open fails with relative URLs in IE (When using the base tag)

Problem

I'm using the base tag to resolve relative URLs to a specific point in some dynamically generated .html pages.

This works great until I try to use Window.open in javascript. Firefox resolves everything fine, but IE resolves the URL to the displayed URL.

Is there an IE work around for this?

I'd like to avoid

Combining the URL with the href in the base tag via Javascript/jQuery. (Unless it's bullet proof. Recognizing the difference between non-relative urls and relative ones, handling the existince of '/' or none '/' when combining, etc...).

Even if you have such a solution. A built in one would be preferred (a matter of formatting my relative URLs to make IE happy?, or whatever).

Example

<html>
  <head>
    <base href="http://stackoverflow.com" />
    <script type="text/javascript">
    showWindowPopupFullScreen = function(URL) {
        var pageWidth = screen.availWidth;
        var pageHeight = screen.availHeight;
        var popup = window.open(URL, 'Window', 'height=' + pageHeight + ',width=' + pageWidth + ',top=0,left=0,resizable');
        if (window.focus) {
            popup.focus();
        }
    }
    </script>
  </head>
  <body>
    <a href="javascript:showWindowPopupFullScreen('users/402706/brandon-boone')">test</a>
  </body>
</html>   
like image 307
Brandon Boone Avatar asked Oct 05 '10 20:10

Brandon Boone


People also ask

What is the purpose of base href tag?

The href attribute specifies the base URL for all relative URLs on a page.

What is a base URL?

Base URL: The consistent part or the root of your website's address. For example, http://www.YourDomain.com. Relative URL: The remaining path given after the base URL. For example, /contact_us, /seo/blog/new_post.

What is the base tag in html?

Definition and Usage. The <base> tag specifies the base URL and/or target for all relative URLs in a document. The <base> tag must have either an href or a target attribute present, or both. There can only be one single <base> element in a document, and it must be inside the <head> element.

What does the base element do?

The <base> HTML element specifies the base URL to use for all relative URLs in a document. There can be only one <base> element in a document. A document's used base URL can be accessed by scripts with Node.


1 Answers

No idea whether this will work - it might or might not, depending on IE's internal workings - but you could try whether this gets translated properly:

<a href="users/402706/brandon-boone" 
   onclick="showWindowPopupFullScreen(this.href)">test</a>
like image 195
Pekka Avatar answered Sep 29 '22 19:09

Pekka