JavaScript: ubicación.href para abrir en una nueva ventana / pestaña?
Tengo un archivo JavaScript de un desarrollador externo. Tiene un enlace has que reemplaza la página actual con el destino. Quiero tener esta página abierta en una nueva pestaña.
Esto es lo que tengo hasta ahora:
if (command == 'lightbox') {
location.href="https://support.wwf.org.uk/earth_hour/index.php?type=individual";
}
¿alguien Puede ayudarme?
4 answers
window.open(
'https://support.wwf.org.uk/earth_hour/index.php?type=individual',
'_blank' // <- This is what makes it open in a new window.
);
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-03-27 06:23:57
Si desea usar location.href
para evitar problemas emergentes, puede usar una referencia <a>
vacía y luego usar javascript para hacer clic en ella.
Algo así como en HTML
<a id="anchorID" href="mynewurl" target="_blank"></a>
Luego haga clic en javascript de la siguiente manera
document.getElementById("anchorID").click();
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-09-05 09:52:39
Puede abrirlo en una nueva ventana con window.open('https://support.wwf.org.uk/earth_hour/index.php?type=individual');
. Si desea abrirlo en una nueva pestaña, abra la página actual en dos pestañas y luego alllow el script a ejecutar para que se obtengan tanto la página actual como la nueva página.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-07-21 19:21:23
$(document).on('click','span.external-link',function(){
var t = $(this),
URL = t.attr('data-href');
$('<a href="'+ URL +'" target="_blank">External Link</a>')[0].click();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span data-href="http://stackoverflow.com" class="external-link">Stackoverflow (Click Me)</span>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-05-13 14:11:49