Elxis CMS Forum

Support => General => Topic started by: xmanhattan on January 21, 2026, 16:16:55

Title: method to open html url in new window using javascript
Post by: xmanhattan on January 21, 2026, 16:16:55
Hello,

I have a separate html file that loads an image within the content of a page but instead it downloads the html page.
I don't know why but this used to work.

I tried the following using Javascript but it didn't work:
Code: [Select]
<button id="openButton">Open Example.com</button>
<script>
    document.getElementById('openButton').addEventListener('click', function() {
        window.open('https://www.example.com', '_blank', 'width=800,height=600, resizable=yes, noopener');
    });
</script>

I can send you a link to the html page via pm to see why I have it separate.
Title: Re: method to open html url in new window using javascript
Post by: xmanhattan on January 24, 2026, 16:31:53
Found the solution  ;D
The problem was in .htaccess
Solution was this line: AddType text/html .html
Title: Re: method to open html url in new window using javascript
Post by: datahell on January 25, 2026, 20:20:45
Avoid using window.open, it is outdated method.
If it is for Elxis, then if mediabox is loaded you can simple use  data-mediabox attribute in your link and Elxis will open it in with mediabox (lightbox):

<a href="https://www.example.com/something/mypicture.jpg" title="My picture" data-mediabox="mypicture">open image</a>

The value of data-mediabox can be anything but if 2 or more links have the same data-mediabox value then it will automatically generate a gallery.

If mediabox is not loaded you can load it like this:
eFactory::getDocument()->loadMediabox();

You can put the above line in your template to make sure mediabox is always loaded. Mediabox can load in lightbox window many-many things, not just images. Events get handled automatically, so you dont have to type any javascript. So, dont use a button but a link instead. You can also make the link look like a button if you want by supplying a CSS class.

With a default button style link (small inline):
<a href="https://www.example.com/something/mypicture.jpg" title="My picture" data-mediabox="mypicture" class="elx5_smbtn">open image</a>

With a default button style link (big 100% width):
<a href="https://www.example.com/something/mypicture.jpg" title="My picture" data-mediabox="mypicture" class="elx5_btn">open image</a>

With a default button style link (big inline):
<a href="https://www.example.com/something/mypicture.jpg" title="My picture" data-mediabox="mypicture" class="elx5_btn elx5_ibtn">open image</a>

You can also apply colours to your button-style link by using addon classes like: elx5_sucbtn, elx5_errorbtn, elx5_warnbtn

Example (big inline success button-style link):
<a href="https://www.example.com/something/mypicture.jpg" title="My picture" data-mediabox="mypicture" class="elx5_btn elx5_ibtn elx5_sucbtn">open image</a>
Title: Re: method to open html url in new window using javascript
Post by: xmanhattan on January 26, 2026, 09:55:02
Datahell, Thank you for the great CMS and advice that you always give!
I am sending you a pm.