I have a game made in vb.net. I am encountering an issue when using window.open in a javascript section.
Below you can see my .aspx page.
In the script tag near the bottom, you will see this line:
window.open('../game/map/?worldID=' + worldID, 'mapdisplay', 'titlebar=yes,width=500,height=900');
So this line is working. When it is reached, it opens the game world.
But the line before it, which is a console.log is never fired.
Additionally, I have some javascript alerts and console.logs in the code behind file, which you can find below.
But those are also never fired.
HOWEVER, this is all very strange to me. If I comment out the window.open
line, all the console.logs and alerts do fire! But of course the new window doesn't open.
Could there be a reason as to why window.open
is blocking my javascript console.logs and alerts?
.aspx page:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="OpenWorldMap.aspx.vb" Inherits="game.OpenWorldMap" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Open World</title>
<script src="../scripts/world.js"></script>
</head>
<body>
<form id="frmOpenGame" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<input type="hidden" name="worldMap" id="worldMap" value="false" />
<asp:HiddenField ID="hfWorldMap" runat="server" Value="0" />
</body>
<script>
const urlParams = new URLSearchParams(window.location.search);
const worldID = urlParams.get('worldID');
// this console.log line never works unless I comment out the window.open line below it
console.log("Opening World");
window.open('../game/map/?worldID=' + worldID, 'mapdisplay', 'titlebar=yes,width=500,height=900');
</script>
</html>
My vb code behind page:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim worldID As Guid
Dim worldLockedBy As String = ""
Try
worldID = New Guid(Request.QueryString("worldID"))
Catch ex As Exception
Response.Write("An error has occured")
Response.End()
End Try
worldLockedBy = gme_IsWorldLocked(worldID.ToString)
// none of my alerts or console.logs fire unless I comment out the window.open
If String.IsNullOrEmpty(worldLockedBy) Or worldLockedBy.ToUpper = utils.myUserID Then
ScriptManager.RegisterStartupScript(Me.Page, Me.Page.GetType, "z", "alert('You can now enter this world!');", True)
ScriptManager.RegisterStartupScript(Me.Page, Me.Page.GetType, "z", "console.log('You can now enter this world!');", True)
Else
worldLockedBy = gme_IsWorldLocked(worldID.ToString, True)
ScriptManager.RegisterStartupScript(Me.Page, Me.Page.GetType, "z", "alert('This world is full');", True)
ScriptManager.RegisterStartupScript(Me.Page, Me.Page.GetType, "z", "console.log('This world is full');", True)
End If
End Sub
question from:https://stackoverflow.com/questions/65927958/is-window-open-blocking-my-other-lines-of-javascript